2

I have an assembly that I built which will be dynamically loaded into my application. However, I would like to make a copy of this assembly and load it as well, but it turns out that this results in unwanted behavior:

If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

The link above to my original question explains that although I have 2 of the same assemblies, they both read from their own xml settings file. So, is it possible to programmatically 'rebuild' an existing assembly so that it's identity changes, but still has the same structure?

Any alternatives to the same result are really appreciated too.

Community
  • 1
  • 1
Daniel Minnaar
  • 5,865
  • 5
  • 31
  • 52
  • You can use an IL rewriting library to change the assembly name. Can you tell us why you need a copy of an assembly? – usr Sep 14 '15 at 09:50
  • The existing plugin architecture (different assembly signatures) allows for the execution of different logic per plugin. Going forward, I want to re-use a generic assembly to execute the same logic with different parameters loaded from settings file (the xml). – Daniel Minnaar Sep 14 '15 at 09:56
  • 1
    That architecture sounds really cumbersome. Can you not pass the configuration as an object to the generic assembly? – usr Sep 14 '15 at 10:10

2 Answers2

2

You can try to copy and rename it. But you will still have the same namespaces.

Renaming of .Net assemblies

Isolating assemblies can be achieved with Application Domains.

https://msdn.microsoft.com/en-us/library/ms173138%28v=vs.90%29.aspx

The drawback of this is that the communication is complicated.

Community
  • 1
  • 1
F. Fix
  • 131
  • 1
  • 3
2

Maybe the question here isn't how to rebuild, but how to reload it. You'll need to create a different AppDomain and load the new assembly into it.

Take a look here: Using AppDomain to Load and Unload Dynamic Assemblies

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162