質問

We get an assembly from a third party, e.g. Example.dll. Recently the supplier introduced some breaking changes, but didn't change the name of the assembly. Can I rename the new assembly to e.g. Example2.dll and load it dynamically using reflection? It is not strongly named.

役に立ちましたか?

解決

Yes, you can rename it, since it's not strongly named, However, that won't change the namespaces the assembly uses, and it will conflict with the other assembly if they are loaded in the same AppDomain.

The only solution I can think of, assuming you want to use both versions at the same time, is to load it in a separate AppDomain and use proxies to make the calls. I'm not going to go into detail on how to do that though, as it can get very complex. My advise, push back to the vendor to get the breaking code corrected, or to give you a renamed assembly.

Here's a reference to get you started: http://msdn.microsoft.com/en-us/library/yk22e11a(v=vs.110).aspx

他のヒント

Yes you can load any assembly by name by calling Assembly.LoadFile or Assembly.LoadFrom or similar methods. The recommended method is LoadFrom as it loads the assembly into the default load context and also loads the dependent assemblies. But remember that the actual AssemblyName does not change by file rename. There are tools out there that would change the assembly name for you as well though.

I did exactly this with the AutoMapper dll. I needed both versions in my solution but just included the non-standard version in my application project (in a dll folder), and added this section to runtime part of the config file.

  <dependentAssembly>
    <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
    <codeBase version="6.1.1.0" href="dlls\AutoMapper.dll" />
  </dependentAssembly>

I just need to remember to manually update the dll folder if the 3rd party dll changes (we get it from Nuget).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top