Assembly.LoadFrom how behaves on multi version dll

时间:2017-10-12 10:22:46

标签: c# .net .net-assembly

I've a dll with 2.0.0.1 version in one server which can be downloaded by accessing http://someipaddress/assembly/test.dll and I'm having another application which need to download this test.dll and have to access those methods.

When surfing for this, i've got three different methods to do, 1. Assembly.LoadFrom() 2. Assembly.LoadFile() 3. Assembly.Load()

I've tried Assembly.LoadFrom("http://someipaddress/assembly/test.dll")

Now i've replaced test.dll with 2.0.0.2 version and What will happen the application download 2.0.0.2 test.dll and already downloaded test.dll 2.0.0.1. Application which dll will refer? Will it use existing test.dll 2.0.0.1 since its already downloaded while accessing test.dll 2.0.0.2?

Please suggest on this.

1 个答案:

答案 0 :(得分:0)

这取决于你如何引用程序集。默认情况下,如果没有绑定重定向,则新的dll将导致异常。您可以通过在应用程序的配置文件中指定绑定重定向规则来解决此问题;

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Test" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.0.0.2" newVersion="2.0.0.2" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

但是你需要在获得新版本的dll时更新它。