Home Assembly Binding .Net 4.0 to .Net 4.5.2
Reply: 0

Assembly Binding .Net 4.0 to .Net 4.5.2

Wes
1#
Wes Published in 2018-01-12 21:20:13Z

I've recently updated my project from .Net 4.0 to .Net 4.5.2 and now the assembly binding behavior seems to behave differently.

It seems to be trying to resolve all assembly references that an assembly was built against as soon as it enters that assembly. The behavior I was seeing with .Net 4.0 was it would only try to resolve references used in a method/property before entering that specific method/property, not the entire assembly.

For example...

  • "EntryApp.exe" has a reference to "Library1.dll"
  • "Library1.dll" has a reference to "Library2.dll"
    • "Library1.dll" is registered in the GAC
  • "Library1.dll" and "Library2.dll" are installed in different locations

Then "Library1.dll" dynamically loads "Library2.dll" in the static constructor like so...

static Library1Object() { Assembly.LoadFrom("<Path to Library2.dll>" }

All of this worked great in .Net 4.0 however; now that I've updated to .Net 4.5.2 when EntryApp.exe calls...

var o = new Library1Object()

I get a "Could not load file or assembly Library2" exception. Hooking a remote debugger up to it I see that it never enters the static constructor to dynamically load "Library2.dll".

One more piece is that registering "Library2.dll" in the GAC is not an option.

Update: Invoking construction of the type through reflection fixes this issue; I used the following.

System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Library1Object).TypeHandle);

However, this cannot be my permanent fix. Any ideas why the runtime is trying to resolve references before calling my static constructor?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.380497 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO