lundi 20 juillet 2020

Same module loaded twice in AppDomain on .net core

I have code running in both .net core and framework. The general idea is that I call a method in a DLL by reflection. To do so, I first create an Assembly and then call a method inside it. The actual logic is I need pretty complicated but the bottom line is that on .net core, the same module is loaded twice into the current App Domain where on framework, it isn't.

Here is a sample of this:

Assembly assembly = Assembly.LoadFile(pathToMyDll) //<--- Line 1
AppDomain.CurrentDomain.Load(assembly.GetName()); //<-- Line 2

Now I know you should never do this but if you do, .net framework will contain only one copy of the assembly in the current AppDomain while .net core will contain two that are exactly the same. One is created after line 1 and the other after line 2. Calling line 2 a second time does nothing. Why would this happen? Why would two assemblies be loaded into the AppDomain this way on core?

Tests were done with .net core 3.1 and framework 4.7.2.

Thanks.





Aucun commentaire:

Enregistrer un commentaire