0

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...

5 Answers 5

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
Have you tried setting (in Properties window) the reference property "Specific Version" to True ?
0

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.

1 Comment

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)
0

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

2 Comments

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...
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? =)
0

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.

2 Comments

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?
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.
0

At the end I solved this as in my other question, renaming the TestFunctions.dll according to the project that uses it. It's more handwork but at least it works.

I don't know if some of the other answers will work too because I don't have much time for testing them. Sorry people. Thanks for the help!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.