diff --git a/mediaportal/MPE/MpeCore/Classes/Util.cs b/mediaportal/MPE/MpeCore/Classes/Util.cs index 06badf272ee..8575cd8c5da 100644 --- a/mediaportal/MPE/MpeCore/Classes/Util.cs +++ b/mediaportal/MPE/MpeCore/Classes/Util.cs @@ -100,14 +100,17 @@ public static bool IsPlugin(string pluginFile) return false; } Assembly pluginAssembly = null; + var pluginDllLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins", "Windows"); + ResolveEventHandler handler = new ResolveEventHandler(delegate (object sender, ResolveEventArgs args) + { + int idx = args.Name.IndexOf(','); + string pluginFullPath = Path.Combine(pluginDllLocation, (idx > 0 ? args.Name.Substring(0, idx) : args.Name) + ".dll"); + return Assembly.LoadFrom(pluginFullPath); + }); + + AppDomain.CurrentDomain.AssemblyResolve += handler; try { - var pluginDllLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins", "Windows"); - AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate (object sender, ResolveEventArgs args) - { - var dllName = Path.Combine(pluginDllLocation, args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"); - return Assembly.LoadFrom(dllName); - }); pluginAssembly = Assembly.LoadFrom(pluginFile); } catch (BadImageFormatException) @@ -119,45 +122,52 @@ public static bool IsPlugin(string pluginFile) MessageBox.Show(string.Format("Error adding plugin depdendency for {0}.\nException message: {1}", pluginFile, ex.Message)); return false; } - if (pluginAssembly != null) + try { - try + if (pluginAssembly != null) { - Type[] exportedTypes = pluginAssembly.GetExportedTypes(); - - foreach (Type type in exportedTypes) + try { - if (type.IsAbstract) - { - continue; - } - if (type.GetInterface("MediaPortal.GUI.Library.ISetupForm") != null) - { - return true; - } - if (type.GetInterface("MediaPortal.GUI.Library.IPlugin") != null) - { - return true; - } - if (type.GetInterface("MediaPortal.GUI.Library.IWakeable") != null) - { - return true; - } - if (type.GetInterface("TvEngine.ITvServerPlugin") != null) - { - return true; - } - if (type.IsClass && type.IsSubclassOf(typeof(GUIWindow))) + Type[] exportedTypes = pluginAssembly.GetExportedTypes(); + + foreach (Type type in exportedTypes) { - return true; + if (type.IsAbstract) + { + continue; + } + if (type.GetInterface("MediaPortal.GUI.Library.ISetupForm") != null) + { + return true; + } + if (type.GetInterface("MediaPortal.GUI.Library.IPlugin") != null) + { + return true; + } + if (type.GetInterface("MediaPortal.GUI.Library.IWakeable") != null) + { + return true; + } + if (type.GetInterface("TvEngine.ITvServerPlugin") != null) + { + return true; + } + if (type.IsClass && type.IsSubclassOf(typeof(GUIWindow))) + { + return true; + } } } + catch (Exception e) + { + MessageBox.Show("Exception " + e.Message); + return false; + } } - catch (Exception e) - { - MessageBox.Show("Exception " + e.Message); - return false; - } + } + finally + { + AppDomain.CurrentDomain.AssemblyResolve -= handler; } return false; }