3

I have developed a console utility that performs some operations against a server application. Due to the nature of the server app I'm working with, I need to execute this utility on the server.

The problem is that the utility is referencing a common DLL that has previously been deployed to the server's GAC. Since the common DLL's deployment, it has been updated and my utility relies on these updates. I am unable to update the DLL in the GAC due to company policy regarding deployment.

By default my utility will use the outdated DLL in the GAC. Is there a way I can force it to use the updated DLL (e.g. by specifying a path on the file system)?

starblue
  • 55,348
  • 14
  • 97
  • 151
Alex Angas
  • 59,219
  • 41
  • 137
  • 210

6 Answers6

3

Does the updated DLL not have a new version number? I would expect that if you force the reference to use the right version number, it should pick up the local one.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

Unfortunately, GAC tends to play a trump card - but if you have changed the version, then the GAC resolve should fail (as long as you have "Specific Version" set to true in the IDE), allowing it to load the local version?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
2

The Assembly class has some methods to load assemblies from specific locations.

Assembly.LoadFrom has a few overloads

EDIT: There is a way to specify, via configuration file, where to look for specific assembly versions. I can't recall exactly.

Megacan
  • 2,510
  • 3
  • 20
  • 31
  • If you have any further information on the configuration file method that would be great. – Alex Angas Feb 23 '09 at 16:53
  • http://msdn.microsoft.com/en-us/library/7wd6ex19(vs.71).aspx Assembly binding and assembly base tags. Hope it helps – Megacan Feb 23 '09 at 17:00
1

As foson suggests, use codebase in your console's config file. Example is shown below (change publicKeyToken, name, version and href appropriately).

<runtime> 
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
  <dependentAssembly> 
     <assemblyIdentity name="myCommonDll" publicKeyToken="32ab4ba45e0a69a1" culture="neutral" />
     <codeBase version="2.0.0.0" href="file://C:\Users\djpiter\Documents/myCommon.dll"/>
  </dependentAssembly> 
 </assemblyBinding> 
</runtime> 

So that would be the easiest way to force CLR to redirect call to your common DLL from GAC to a version sitting at href location. Your updated common dll should be strong-named just like the one in the GAC with same name, culture, publickeytoken but a new version. The only change, therefore, is in console's config file. You don't need to change reference in console's source code. You can simply keep using existing console app.

SamDevx
  • 2,268
  • 4
  • 32
  • 47
0

You might want to take a look at the AppDomain.AssemblyResolve event.

EDIT: the event is only fired when regular assembly resolution fails, so it does not fit your needs.

Dario Solera
  • 5,694
  • 3
  • 29
  • 34
0

Try using a <codebase> element in the app.config

foson
  • 10,037
  • 2
  • 35
  • 53