tags:

views:

958

answers:

5

Hi I've written a batch execution framework and in it I want (in some scenarios) to load an assembly from the GAC where there may be multiple versions but I just want to load the latest version.
Is this even possible?

TIA

A: 

Linq to Gac can query the GAC. You can load assembly at runtime once you know what you want.

eed3si9n
+2  A: 

You should be able to use a publisher policy with a BindingRedirect. See this SO answer.

Mitch Wheat
+2  A: 

Assembly.LoadWithPartialName(string) will do exactly what you want.

csgero
+1  A: 

Thanks guys I'm trying to do the publisher policy bit at the moment as that would actually suit my needs perfectly. I don't seem to be able to add the policy assembly to the GAC though. It works ok on my dev machine, but won't install on the test server. Using the drag and drop through the shell extension I get:

"A module specified in the manifest of assembly 'policy.3.0.assemblyname.dll' could not be found"

Using gacutil I get "Failure adding assembly to the cache: Unknown Error"

My policy file looks like this:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="*assemblyname*"
                          publicKeyToken="7a19eec6f55e2f84"
                          culture="neutral" />
        <bindingRedirect oldVersion="3.0.0.0"
                         newVersion="3.0.0.1"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Any ideas on this one??

cheers

Ben

Ben
Have you put the assembly itself (with version 3.0.0.1) in the GAC?
csgero
yes, that's in there - what else is it looking for???Are there any differences between the debug and release versions of the assembly that could cause an issue here?
Ben
I've recreated the problem from scratch with a new assembly that has no dependancies (apart from the defaults) itself - all works fine on my local development machine and the same error adding the policy file to the GAC on the server!
Ben
Sorted it http://stackoverflow.com/questions/302239/error-adding-policy-file-to-gac#323207
Ben