瀏覽代碼

Handle exception when loading unsupported assembly

Fixes #1256
Bond-009 6 年之前
父節點
當前提交
f62af07381
共有 1 個文件被更改,包括 14 次插入3 次删除
  1. 14 3
      Emby.Server.Implementations/ApplicationHost.cs

+ 14 - 3
Emby.Server.Implementations/ApplicationHost.cs

@@ -1167,7 +1167,7 @@ namespace Emby.Server.Implementations
             }
             catch (Exception ex)
             {
-                Logger.LogError(ex, "Error loading plugin {pluginName}", plugin.GetType().FullName);
+                Logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName);
                 return null;
             }
 
@@ -1348,8 +1348,19 @@ namespace Emby.Server.Implementations
             {
                 foreach (var file in Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories))
                 {
-                    Logger.LogInformation("Loading assembly {Path}", file);
-                    yield return Assembly.LoadFrom(file);
+                    Assembly plugAss;
+                    try
+                    {
+                        plugAss = Assembly.LoadFrom(file);
+                    }
+                    catch (TypeLoadException ex)
+                    {
+                        Logger.LogError(ex, "Failed to load assembly {Path}", file);
+                        continue;
+                    }
+
+                    Logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file);
+                    yield return plugAss;
                 }
             }