Fail gracefully for IDalamudPlugin check failures

This commit is contained in:
Raymond 2021-08-22 08:03:22 -04:00
parent ca39735022
commit 5303a93a3d

View file

@ -55,13 +55,6 @@ namespace Dalamud.Plugin.Internal
{
// BadImageFormatException
this.pluginAssembly = this.loader.LoadDefaultAssembly();
// InvalidOperationException
this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin)));
if (this.pluginType == default)
throw new Exception("Nothing inherits from IDalamudPlugin");
assemblyVersion = this.pluginAssembly.GetName().Version;
}
catch (Exception ex)
{
@ -73,6 +66,19 @@ namespace Dalamud.Plugin.Internal
throw new InvalidPluginException(this.DllFile);
}
this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin)));
if (this.pluginType == default)
{
this.pluginAssembly = null;
this.pluginType = null;
this.loader.Dispose();
Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.Name}");
throw new InvalidPluginException(this.DllFile);
}
assemblyVersion = this.pluginAssembly.GetName().Version;
// Files that may or may not exist
this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);