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

Assembly Binding .Net 4.0 to .Net 4.5.2

user1792 Published in May 25, 2018, 11:12 am

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.


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.377411 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO