Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade a reference dll in a C# project without recompiling the project

I need to take a built version of an C# application and change one of the reference dll's. What is the best way to do this, I have specific version turned off on the reference dll but as soon as I test replacing the dll with a newer version, I get the "Could not load file or assembly XXXXX, Version=XXXXX. Is there a way to stop the loader from caring about the version of the dll so the dll will just attempt to load?

like image 642
Jeff Lundstrom Avatar asked Sep 22 '09 17:09

Jeff Lundstrom


People also ask

How do I add a reference to a DLL in Visual Studio C++?

Using Visual C++ .In Solution Explorer, select the project. On the Project menu, click Add References. In Visual C++, click References on the Project menu, and then click Add New Reference. In the Add References dialog box, click the tab that corresponds with the category that you want to add a reference to.


1 Answers

Yes, you can do this - see the MSDN article Redirecting Assembly Versions.

You should read the whole document, but it essentially involves either the assembly's publisher creating a 'publisher policy file' or the consumer adding a bindingRedirect to an app.config file, like this (copied directly from the article):

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="myAssembly"
                           publicKeyToken="32ab4ba45e0a69a1"
                           culture="en-us" />
         <bindingRedirect oldVersion="1.0.0.0"
                          newVersion="2.0.0.0"/>
       </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

A few notes:

  • If you haven't explicitly specified your culture (as many don't), it will be "neutral" rather than "en-us".

  • If you don't already know it, you can get the assembly's public key token using the strong name utility, like this: sn -t [AssemblyPath]

like image 189
Jeff Sternal Avatar answered Sep 22 '22 19:09

Jeff Sternal