views:

80

answers:

2

I'm referencing a signed assembly. In runtime it is ok for me to work with any version of that assembly, not just the one I compiled to.

How to achieve this?

+1  A: 

In the IDE, make sure "Specific Version" is set to false against the reference, or add <SpecificVersion>False</SpecificVersion> to the reference in the csproj.

Marc Gravell
@Marc: How will the runtime determine which assembly (out of multiple versions) to load? (I am assuming a signed assembly is placed in GAC).
shahkalpesh
Does this work with signed assemblies?
Yaron Naveh
shahkalpesh
@shahkalpesh - I have no idea; I almost never use GAC
Marc Gravell
@Yaron Naveh - should do. In fact, IIRC it can't *reliably* work as "only use the specific version" **unless** it is signed.
Marc Gravell
A: 

No, that's not going to work. The CLR will verify the assembly version number, expecting to get the one that your main program was compiled against. You would have to use the <bindingRedirect> element in the app.config file to convince it that a different version is okay.

That's a slippery slope. Consider only changing the [AssemblyVersion] attribute if the public interface of the assembly changed and requires clients to be recompiled. Now the exception you'll get is one that identifies a real problem. This is another kind of slippery slope, but one you'll have much more control over.

For comparison, this is the way all the base assemblies in the .NET framework work. There have been many revisions of them between .NET 2.0 RTM and 3.5 SP1, including many invisible hotfixes. But the [AssemblyVersion] is still 2.0.0.0, Microsoft only modifies the [AssemblyFileVersion].

Hans Passant