C# Load different versions of assembly to the same project

后端 未结 3 853
失恋的感觉
失恋的感觉 2020-12-20 16:27

I\'m creating some tool what performs several operations like NUnit. Inside this tool I open .dll assembly and invoke methods form it to run some test.

Everything

相关标签:
3条回答
  • 2020-12-20 16:42

    The CLR does support loading multiple versions of strongly named assemblies into the same AppDomain. This only works though if your assemblies are strongly named and each one has a different version than the other.

    I'm guessing it's more likely that you are dealing with unsigned assemblies. If that is the case then what you're asking for isn't really possible. Once a given assembly is loaded into an AppDomain it will remain there until the AppDomain is unloaded. To get this to work you will have to abstract out all of the work around the loaded assemblies into a separate AppDomain and use a new AppDomain for every assembly

    0 讨论(0)
  • 2020-12-20 16:51

    Try like this:

    string dllFile = "C:\\sample.dll";
    Assembly asmLoader = Assembly.LoadFile(dllFile);
    Type[] types = asmLoader.GetTypes();
    

    Since all resources from the assembly cannot be reloaded/replaced it's assembly resources while application is still running. It will only be replaced/removed when application is unloaded or the that Assembly that holds it.

    Use LoadFile() method. Hope it helps.

    0 讨论(0)
  • 2020-12-20 17:00

    To expand on JaredPar's answer, you will need to create a new AppDomain and use Remoting to communicate between the two.

    Check out http://msdn.microsoft.com/en-us/library/kwdt6w2k(v=vs.85).aspx to help get you started.

    0 讨论(0)
提交回复
热议问题