0

We have 2 different applications (developed with .NET):

1st App: A Winservice.

2nd App: A Desktop App.

The Desktop App is loading the assembly from the GAC. The Winservice was in the past doing the same thing, but now we need that the Winservice loads THE SAME ASSEMBLY from another location.

But the GAC is winning and we can´t make this Winservice (using codebase in the app.config) to load the assembly. It always get the GAC´s one.

If we remove the GAC´s one. It works. But we need the other behavior. Desktop from the GAC and Winservice from the defined path in the codebase.

Is this possible without changing the version of the Assembly?

acromm
  • 880
  • 13
  • 24
  • Where is the assembly relative to the Winservice? Or is it an unknown dynamic value? – mclaassen Aug 12 '14 at 18:47
  • Also look here: http://stackoverflow.com/questions/1373100/how-to-add-folder-to-assembly-search-path-at-runtime-in-net – mclaassen Aug 12 '14 at 18:48
  • The location of the assembly is being loaded dynamicly (using CurrentDomain.CreateInstanceAndUnwrap()). From a location that is not a relative to the Winservice basepath. – acromm Aug 12 '14 at 18:56
  • @mclaassen I alredy try currentDomain.AssemblyResolve but the event never gets fired. Maybe because the way we are loading the Assemblies. – acromm Aug 12 '14 at 18:59

1 Answers1

1

This is not possible without some kind of work around that modifies the assembly. In short, the GAC always wins. Period. If an assembly has a strong name the GAC is always checked first. Even if you load it into memory as a byte array and use Assembly.Load(byte[]), the strong name will be checked and if it is a GAC'd assembly it gets loaded from the GAC.

A couple possible work arounds:

  • Bump the assembly version.
  • Resign the assembly with a different strong name key. Build the service referencing this version.
Mike Zboray
  • 39,828
  • 3
  • 90
  • 122