Weird behaviour when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load

后端 未结 2 1985
广开言路
广开言路 2021-01-18 20:49

Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load

I have encountered a weird behavior when loading assemblies with Assembly.

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 21:42

    That's not weird. As per the documentation, loading with Load and LoadFrom will place the assemblies in different contexts. This might help.

    1. Any explanation why the CLR ignores the already loaded assembly?

    Because they're in a different context.

    1. Any idea how can I alleviate this problem?

    Load from the same context, or help the CLR find the assembly, perhaps by attaching a handler to AppDomain.AssemblyResolve.

    Alternative

    If the location you are loading assemblies from is a subfolder under AppDomain.BaseDirectory you can simply add an entry to your App.config:

    
       
          
             
          
       
    
    

    http://msdn.microsoft.com/en-us/library/823z9h8w.aspx

提交回复
热议问题