Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference Multiple Versions of 1 Assembly

Status
Not open for further replies.

PGO01

Programmer
Jan 8, 2008
156
GB
Is it possible to reference various different versions of the same assembly in C#?

For example I have an assembly 'C:/MyAssemblies/v1/Test.dll' and another version 'C:/MyAssemblies/v2/Test.dll'.

Now I want to use both dll's in my code...

I've tried adding the reference to my solution but I get the message "A reference to the component [my dll] already exists."

I would have thought that this would be possible and I could just use aliases or something?

 
I can't add the 2nd reference because they share the same name. Even though they are different versions and in different locations.

Help!
 
why would you want to do this? this will become a maintenance nightmare.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I'd like to instantiate an obect based on user input. For example:

Code:
[COLOR=blue]object[/color] myConn;
[COLOR=blue]if[/color] (something)
{
    ([COLOR=teal]Version1Connection[/color])myConn = [COLOR=blue]new[/color] [COLOR=teal]Version1Connection[/color]();
}
[COLOR=blue]else[/color]
{
    ([COLOR=teal]Version2Connection[/color])myConn = [COLOR=blue]new[/color] [COLOR=teal]Version2Connection[/color]();
}
 
no, why would you want multiple versions of the same assembly. this will become a maintenance nightmare.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Why would it be a maintenance nightmare?

I can think of many advantages especially if you program a lot for 1 or 2 pieces of software where there are many live versions around.

You could have a generic set of classes that can be switched from one version to the next at runtime... or you could have a program that checks the version of the 'target' application and adjusts its 'pointers' appropriately.

Pete
 
in this scenario you have 2 distinct objects, not 2 versions of object. because the objects are distinct they can reside in the same assembly (namespace even).

having 2 versions of the same object in different assemblies would look like this
Code:
IConnection v1 = new [COLOR=blue]MyAssembly.NameSpace.Myconnection()[/color];
IConnection v2 = new [COLOR=red]MyAssembly.NameSpace.Myconnection()[/color];
where MyAssembly.NameSpace.Myconnection references ~/v1/assembly.dll
and MyAssembly.NameSpace.Myconnection references ~/v2/assembly.dll

that's the problem.

when an application is compiled it pulls all the assemblies into the root(or bin for web) directory. at this point one assembly would overwrite the other. If this is possible I think the assemblies must be signed (strongly named) and stored in the GAC (general assembly cache)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top