Howto load assemby at runtime before AssemblyResolve event?

前端 未结 2 1150
日久生厌
日久生厌 2020-12-01 15:06

Actually i tried to implement some kind of \'statically linked\' assemblies, within my solution. So i tried the following:

  • Adding a reference to my assembly wi
2条回答
  •  青春惊慌失措
    2020-12-01 15:42

    The CLR Binder doesn't know that LoadMyAssemblies() does the same thing as the AssemblyResolve event, and that they are both trying to look for the same assembly and load it.

    AssemblyResolve event always gets fired at the point at which the Binder decides that it has searched all possible locations (that are searchable wrt that application) and could not find a match.

    This begs the original question, which is, why would you want to statically link your managed assemblies? Read this thread for a lot of discussion on this Static linking advantages

    I'll go ahead and answer the part on how to avoid hitting the AssemblyResolve event 1) Put the assembly into the GAC. As far as the Binder is concerned, the GAC always wins. 2) Place your assembly in the probing path and make sure that the Binder picks it up (look for the article 'How the runtime locates assemblies' on MSDN for more on this).

提交回复
热议问题