Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous Reference Error

I am getting the following error, intermittently:

Could Not load file or assembly 'com.mycompany.myapp' or one of its dependencies. The located assembly's manifest does not match the assembly reference.

I have a library of Ajax user controls that I built and compiled to a DLL. This project has a references to Project A (com.mycompany.myapp). My main web application has a reference to this DLL and also has a reference to Project A. On occasion, this error will occur when I try to rebuild my web application. It seems like the references to Project A are getting out of sync between the DLL and the web application.

This can only be fixed by rebuilding the DLL, removing the reference to the DLL from the web application, re-adding the reference, and then rebuild the web application. Can anyone explain why this is occurring and how to prevent this error from cropping up?

I am looking for a solution that will allow solve this issue so that I may distribute this DLL without worry that it will need to be rebuilt and deployed intermittently.

like image 734
jason Avatar asked Apr 12 '13 18:04

jason


1 Answers

If you have all your projects inside the same solution, you need to make sure that they're all project references and not file references. You can check this by right clicking the project and going to properties => references.

In your reference list you'll see a column named "copy local". If this is set to set to false it means you're referencing it by file instead of project (which doesn't update the DLL after you build it). To solve it, remove the reference and add it again (making sure you reference it from your solution, not by referencing the DLL on your hard-drive).

If you don't have all projects inside the same solution, then this is normal behavior. Suppose your Ajax controls library is outside of the solution.

The starting situation would be something like this:

  • Ajax references A (version 1)
  • Project references A (version 1)
  • Project references Ajax (version 1)

After you build your solution (without the Ajax project inside it) you will have the following situation:

  • Ajax references A (version 1)
  • Project references A (version 2)
  • Project references Ajax (version 1)

As you can see, the compiler suddenly needs a reference to A version 1 and version 2, so that's impossible and it gives you an error. This would also explain why it works when you do a rebuild and delete the DLL and add it again.

The solution here would be to add the Ajax-project to your solution and rebuild it every time.

like image 63
Kenneth Avatar answered Sep 21 '22 13:09

Kenneth