Merge pull request #1258 from Bond-009/fixpluginload
Handle exception when loading unsupported assembly
This commit is contained in:
commit
3738f95871
|
@ -1167,7 +1167,7 @@ namespace Emby.Server.Implementations
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,10 +1181,32 @@ namespace Emby.Server.Implementations
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Loading assemblies");
|
Logger.LogInformation("Loading assemblies");
|
||||||
|
|
||||||
AllConcreteTypes = GetComposablePartAssemblies()
|
AllConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray();
|
||||||
.SelectMany(x => x.ExportedTypes)
|
}
|
||||||
.Where(type => type.IsClass && !type.IsAbstract && !type.IsInterface && !type.IsGenericType)
|
|
||||||
.ToArray();
|
private IEnumerable<Type> GetTypes(IEnumerable<Assembly> assemblies)
|
||||||
|
{
|
||||||
|
foreach (var ass in assemblies)
|
||||||
|
{
|
||||||
|
Type[] exportedTypes;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
exportedTypes = ass.GetExportedTypes();
|
||||||
|
}
|
||||||
|
catch (TypeLoadException ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "Error getting exported types from {Assembly}", ass.FullName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Type type in exportedTypes)
|
||||||
|
{
|
||||||
|
if (type.IsClass && !type.IsAbstract && !type.IsInterface && !type.IsGenericType)
|
||||||
|
{
|
||||||
|
yield return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CertificateInfo CertificateInfo { get; set; }
|
private CertificateInfo CertificateInfo { get; set; }
|
||||||
|
@ -1348,8 +1370,19 @@ namespace Emby.Server.Implementations
|
||||||
{
|
{
|
||||||
foreach (var file in Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories))
|
foreach (var file in Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Loading assembly {Path}", file);
|
Assembly plugAss;
|
||||||
yield return Assembly.LoadFrom(file);
|
try
|
||||||
|
{
|
||||||
|
plugAss = Assembly.LoadFrom(file);
|
||||||
|
}
|
||||||
|
catch (FileLoadException ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "Failed to load assembly {Path}", file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file);
|
||||||
|
yield return plugAss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user