views:

1368

answers:

5

I have a project like this:

Test Solution

Project TestApplication
 References: TestFunctions.dll(ver 1.0.0.0),Project TestDLL
Project TestDLL
 References: TestFunctions.dll(ver 1.0.0.1)

In the application when i make a call to TestDLL.Methodx() inside it calls TestFunctions.HelloWorld() but it gives a MissingMethodException because TestFunctions.HelloWorld() only exists in TestFunctions.dll(ver 1.0.0.1) and it tries to call the function in the ver 1.0.0.0 dll...

How can I force it to call to the correct version?

I tried using "extern alias" to no avail...

+2  A: 

Rename referenced dlls to TestFunctions1.0.0.0.dll and TestFunctions1.0.0.1.dll

If the two references have the same name one will be overriden by the other one on compile

Catalin DICU
If i rename TestFunctions.dll(ver 1.0.0.1) to TestFunctions1.dll the reference name changes but then in the code (in Project TestDLL) it doesnt found TestFunctions neither TestFunctions1.This works if you rename the dll in the TestFunctions.dll "Assembly Name"But being a dll used in a lot of proyects and being changed frequently is there another solution or posbuild/prebuild trick to use it with ease?
ase69s
Have you tried setting (in Properties window) the reference property "Specific Version" to True ?
Catalin DICU
A: 

I believe Visual Studio will only allow for one version of a DLL at a time.

Perhaps try loading the 1.0.0.1 version at run-time - Assembly.Load() - to solve this.

Jon Grant
Assembly.Load() is not an option in this case because i would lost all the intellisense stuff, after reading how Assembly.Load()/LoadFrom()/LoadFile() works the results would be the same as referencing statically and its a dll that it will only be changed for a especifict proyect during the development of the proyect or not (only if i need to change some Function inside the dll)
ase69s
A: 

The only way you can "force" it to call the correct DLL is to have the correct DLL referenced, i.e. you'll need to remove the reference to v1.0.0.0 and add a reference to v1.0.0.1

Rob
But in some cases the testApplication project needs to use a different version of the TestFunctions.dll than the one referenced in the TestDLL project so it has to be this way...
ase69s
The simple answer is that it's not possible - you can't have two versions of the same DLL loaded into one process as this would cause a huge amount of confusion.Perhaps if you explain *why* you want to be able to do this, we can find you a way to solve your underlying problem? =)
Rob
A: 

You'd have to sign your assemblies (give them a strong name), and put them in the GAC, or if you are using Visual Studio, you'd have to build the two different versions into different output folders, and set the references to the file path, not the project output. Then in the properties for the reference, you can change the Specific Version to true.

Richard Hein
I cant sign the TestFunctions.dll because some of its references are incompatible with signing (or so says visual studio). I especified "copy local=false" and "specific version=true" in the TestFunctions.dll reference of both projects (TestApplication and TestDLL) and the error is the same (MissingMethodException). Have i missed any step of your explanation?
ase69s
I tested this before answering, it was a simple set up, but it works. Make sure you point your references to the correct path for each version of TestFunctions.dll. The TestApplication and TestDLL references should be different ... they have to point to two different locations on the file system, matching two different versions of TestFunctions.dll.
Richard Hein
A: 

At the end i solved this as in my other question...renaming the TestFunctions.dll acordingly to the proyect that uses it...its more handwork but at least it works...

I dont know exactly if some of the other answers will work too because i dont have much time for testing them...sorry people and thanks for the help!

ase69s