Created
March 21, 2013 20:25
-
-
Save majimenezp/5216394 to your computer and use it in GitHub Desktop.
With the new Assembly type scanner, when nancy search for the dll containing references to Nancy, where tries to load a dll that not are managed code(for example SQLite.Interop.dll or libzmq.dll) the method LoadAssembliesWithNancyReferences fromthe class AppDomainAssemblyTypeScanner throw a BadImageException. It's only need a try catch to not sh…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void LoadAssembliesWithNancyReferences() | |
{ | |
if (nancyReferencingAssembliesLoaded) | |
{ | |
return; | |
} | |
UpdateAssemblies(); | |
foreach (var directory in GetAssemblyDirectories()) | |
{ | |
var existingAssemblyPaths = | |
assemblies.Select(a => a.Location).ToArray(); | |
var unloadedAssemblies = Directory | |
.GetFiles(directory, "*.dll") | |
.Where(f => !existingAssemblyPaths.Contains(f, StringComparer.InvariantCultureIgnoreCase)).ToArray(); | |
foreach (var unloadedAssembly in unloadedAssemblies) | |
{ | |
Assembly inspectedAssembly = null; | |
try | |
{ | |
inspectedAssembly = Assembly.ReflectionOnlyLoadFrom(unloadedAssembly); | |
} | |
catch (BadImageFormatException biEx) | |
{ | |
//the assembly maybe it's not managed code | |
} | |
if (inspectedAssembly!=null && inspectedAssembly.GetReferencedAssemblies().Any(r => r.Name.StartsWith("Nancy", StringComparison.OrdinalIgnoreCase))) | |
{ | |
try | |
{ | |
Assembly.Load(inspectedAssembly.GetName()); | |
} | |
catch | |
{ | |
} | |
} | |
} | |
} | |
UpdateTypes(); | |
nancyReferencingAssembliesLoaded = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment