This particular error caused me some headaches so I decided to blog about it in the hope that it'll help some other poor soul! I have a pretty standard MVC 3 project that uses Entity Framework Code First for handling the database side of things. I decided to update my project to ensure it was using the latest version of all of the packages in use on my project (ninject/entity framework/etc). This particular project was using Entity Framework v4.1, which I had previously updated using NuGet without any problems, so I decided to download and install the latest version from NuGet - ver 4.2.
I know after installing any new version of Entity Framework it's always wise to restart Visual Studio and do a clean rebuild of your project but when I went to run this project locally it threw up the following error:
Could not load file or assembly 'EntityFramework, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
It was fairly obvious that my project was looking for the wrong version of EF but I couldn't tell why. I went looking for any hard coded mention of EFv4.1 but nothing was returned. Next I did some searching online but nothing seemed to match my particular error. I took a closer look at the detailed error log and noticed it was looking for the entityframework.dll file but was not finding it.
I took a look in the 'Packages' folder that NuGet installs the files to. I could see 2 Entity Framework folders. One folder was for the older v4.1 and one was for the new v4.2. I took a look inside the v4.2 folder and could see the dll files in there so I knew the files had downloaded. Then I took a look in the v4.1 folder and noticed that the folder structure was different.
- I went back into the v4.2 folder (Packages\EntityFramework.188.8.131.52\lib\) and could see a folder called 'net40' that contained the dll files.
- I cut the 2 files out of there and placed them into the 'Packages\EntityFramework.184.108.40.206\lib' folder (up 1 folder level).
- I went back into Visual Studio, did a rebuild and everything went back to work for me.
Reading back over this post I can't believe how easy and simple the fix was. Up until now NuGet had always worked so it never crossed my mind that it would have botched the update. Hopefully this solution will help you out if you see that dreaded error message. Fingers crossed NuGet won't do anything like that again to me.