Fix introspection of dynamic assemblies
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 7m22s
Build / Build Nuget package (NuGet) (push) Successful in 6m52s
Build / Build Nuget package (CringePlugins) (push) Successful in 7m59s
Build / Build Nuget package (SharedCringe) (push) Successful in 6m17s
Build / Build Launcher (push) Successful in 9m57s

Log incorrect config method instead of throwing exception
This commit is contained in:
2024-11-03 21:51:00 -05:00
parent a087efa4dd
commit cca25e438d
2 changed files with 26 additions and 5 deletions

View File

@@ -34,6 +34,12 @@ public static class IntrospectionPatches
if (AssemblyLoadContext.GetLoadContext(__instance) is ICoreLoadContext || __instance.FullName?.StartsWith("System.") == true)
return true;
if (__instance.IsDynamic)
{
__result = [];
return false;
}
if (AssemblyLoadContext.GetLoadContext(__instance) is ModAssemblyLoadContext or DerivedAssemblyLoadContext)
{
//mods need to look for specific derived types

View File

@@ -2,6 +2,8 @@
using System.Runtime.Loader;
using CringeBootstrap.Abstractions;
using CringePlugins.Utils;
using dnlib.DotNet;
using NLog;
using SharedCringe.Loader;
using VRage.Plugins;
@@ -16,6 +18,8 @@ internal sealed class PluginInstance
private IPlugin? _instance;
private Action? _openConfigAction;
private IHandleInputPlugin? _handleInputInstance;
private static readonly NLog.ILogger Log = LogManager.GetCurrentClassLogger();
public PluginMetadata Metadata { get; }
public PluginInstance(PluginMetadata metadata, string entrypointPath)
@@ -51,11 +55,15 @@ internal sealed class PluginInstance
if (openConfigMethod is not null)
{
//todo: log this and continue without action instead of throwing exception
if (openConfigMethod.ReturnType != typeof(void) || openConfigMethod.IsStatic || openConfigMethod.GetParameters().Length > 0)
throw new InvalidOperationException("OpenConfigDialog method has an incorrect signature");
_openConfigAction = openConfigMethod.CreateDelegate<Action>(_instance);
{
Log.Error("Plugin has OpenConfigDialog method with incorrect signature: {Name}, v{Version} - {Source}",
Metadata.Name, Metadata.Version, Metadata.Source);
}
else
{
_openConfigAction = openConfigMethod.CreateDelegate<Action>(_instance);
}
}
_handleInputInstance = _instance as IHandleInputPlugin;
@@ -76,6 +84,13 @@ internal sealed class PluginInstance
if (_openConfigAction is null)
throw new InvalidOperationException("Plugin does not have OpenConfigDialog method");
_openConfigAction();
try
{
_openConfigAction();
}
catch (Exception ex)
{
Log.Error(ex, "Error opening config: {Exception}");
}
}
}