Assembly.LoadXXX methods and GAC

D

Dilip

I have a situation at work that has me wondering if GAC is causing
more harm than good in my particular scenario.

Our application depends on a third party dll that is installed in the
GAC. This assembly seems to change its build/revision portion of its
version numbers with every new iteration of the software. If I were
to write an application that dynamically loads this assembly using
reflection, and calls its members, there is no way my application can
remain in sync with the third party software, right? I mean, if I
write my application to load a certain version from the GAC using
Assembly.Load and then deploy it and our vendor promptly comes out
with a new version that does not have any significant changes to the
shared assembly but still bumps up the build/revision number, my
application will now stop working because it can't find the right
version, right? Of course when my vendor installs the new software my
application will also be restarted to ensure that I don't make calls
on zombie objects.

I guess my point is Assembly.LoadWithPartialName would've greatly
helped me here. I simply want to pull whatever version of this shared
assembly is present in the GAC.

Either I am missing something blindingly obvious or else I have run
into a legitimate corner case.

Which is it?
 
A

Alberto Poblacion

There is a way that you can redirect your application to use a different
version of the assembly without recompiling your application: Add a
configuration file. The configuration file should be named
yourapplication.exe.config and, among the various things that it can
contain, there is a node called <bindingRedirect oldVersion=...
newVersion=.../> that you can apply to one of the referenced assemblies. The
..Net configuration tool in Control Panel can generate this file, so you
don't need to know the exact structure of the xml that it contains.

However, the "right" way to do things would be for the vendor that provides
the assembly to deliver a Publisher Policy every time that they produce a
new version of the assembly. The Publisher Policy is installed to the GAC,
and it contains the Binding Redirect that instructs the .Net runtime to
redirect requests for previous versions into the new (compatible) version,
so that the users don't have to reconfigure all the possible programs in the
system that might be making use of the assembly in the GAC.
 
D

Dilip

PublisherPolicy seems to be the way to go. Thanks Alberto!! I did
know about redirects and publisher policies but for some reason the
latter slipped my mind.

Are you saying that if I end up having something like this in code:

Assembly.Load("someassembly,version=1.0.0.0......");

and the vendor deploys someassembly ver 1.1.0.0, the publisher policy
will ensure that all requests for 1.0.0.0 versions are redirected to
the new ones?

OK. That seems nice. What if he comes up with 1.3.0.0 later? In
other words is there a way in the publisher policy to redirect a
*range* of older versions to the latest version installed by the
vendor?
 
A

Alberto Poblacion

Dilip said:
PublisherPolicy seems to be the way to go. Thanks Alberto!! I did
know about redirects and publisher policies but for some reason the
latter slipped my mind.

Are you saying that if I end up having something like this in code:

Assembly.Load("someassembly,version=1.0.0.0......");

and the vendor deploys someassembly ver 1.1.0.0, the publisher policy
will ensure that all requests for 1.0.0.0 versions are redirected to
the new ones?

I believe it should work, although I have only tried it out with
statically linked assemblies. If you need to debug the fusion process, you
can use the Fusion Log Viewer (FUSLOGVW,EXE), which will show you the
complete process of searching for an assembly, the places where the runtime
is looking for it, the policies that are aplied, and so on.
OK. That seems nice. What if he comes up with 1.3.0.0 later? In
other words is there a way in the publisher policy to redirect a
*range* of older versions to the latest version installed by the
vendor?

The BindingPolicy allows a range of versions such as 1.2.3.4-1.9.9.9 for
the RequestedVersion, but the NewVersion has to be a specific one, such as
2.0.1.2. So you can redirect a range of older versions to a new one, but you
can't specify thet the "new one" always be automatically the latest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top