Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine where Assembly.Load() searches for assemblies?

I have a VS Add-In that's using a BinaryFormatter to deserialize an object. To resolve the type of this object, it's calling Assembly.Load(objectTypeFullName) but it's triggering an exception because Assembly.Load cannot find the assembly in any of the places it's searching on. The given assembly is sibling to the add-in assembly, but it seems that Assembly.Load() can't find it there.

A possible solution would be to determine where Assembly.Load should look for assemblies.

What should I do?

PS: I'm trying not to put this assembly on GAC because I would need to update it everytime I recompile the assembly.

like image 946
André Pena Avatar asked Oct 15 '10 19:10

André Pena


People also ask

Where does .NET look for assemblies?

For strong-named assemblies, the binding process continues by looking in the global assembly cache. The global assembly cache stores assemblies that can be used by several applications on a computer. All assemblies in the global assembly cache must have strong names.

How does assembly load work?

Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.

What is the method to load assembly given its file name and its path?

LoadFrom(String) Loads an assembly given its file name or path.


1 Answers

You can use AppDomainSetup.PrivateBinPath to add additional private search paths. This can be retrieved via AppDomain.SetupInformation.

Another option is to subscribe to AppDomain.AssemblyResolve in order to override the behavior when it fails to find your assembly.

like image 69
Reed Copsey Avatar answered Sep 30 '22 15:09

Reed Copsey