Skip to content

Instantly share code, notes, and snippets.

@majimenezp
Created March 21, 2013 20:25
Show Gist options
  • Save majimenezp/5216394 to your computer and use it in GitHub Desktop.
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…
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