Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework References go missing between debug and release build

There must be something that I don't understand in the difference between debug builds and release builds and its use of references. I'm using Entity Framework 6 to connect to a database that has previously been set up. I am able to successfully build and run the project while it is in Debug mode. If I change it to release mode I instantly get build errors indicating that the namespaces and types that were just there can no longer be found. I checked and as far as I can tell they both target framework .Net 4.5 which I saw may have been an issue for some other people. I see no difference in what is listed under references in my solution explorer.

I'm using visual studio 2013. Happy to provide any code but I don't know what would be most relevant.

Some of the errors that I'm getting:

The type or namespace name 'Entity' does not exist in the namespace    System.Data' (are you missing an assembly reference?) in Holds.Context.cs
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) in Holds.Context.cs
The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?) in Holds.Context.cs 

Thanks for any guidance that can be provided.

like image 314
BryanP Avatar asked Jun 02 '15 12:06

BryanP


3 Answers

To resolve this I used @OomPiet's answer. For me the steps were as follows:

  1. Switch to Debug Mode
  2. Rebuild solution - Build Successful
  3. Switch to Release Mode
  4. Rebuild solution - Build Failed
  5. In Solution Explorer click on the project that will not build (mine was a unit test project)
  6. Right Click project > Manage NuGet Packages
  7. Ensure Installed packagesis selected
  8. Select EntityFramework
  9. Click Uninstall and close dialog
  10. Click on Solution in Solution Explorer
  11. Right Click > Manage NuGet Packages for Solution
  12. Ensure Installed packagesis selected
  13. Select EntityFramework
  14. Click Manage
  15. Ensure the project which is causing issue is checked
  16. Click OK and close dialog after installing
  17. Click Click on Solution in Solution Explorer
  18. Right Click 'Rebuild Solution'

Now I can switch between Debug and Release without compilation failing. I hope that helps

EDIT: If you have only one project using EF, see @LuckyLikey's comment below where he states to search for EF instead, and install it in that project.

like image 84
Dib Avatar answered Nov 15 '22 16:11

Dib


Switching to release mode then re-installing entity framework on the problem project fixed this issue in my case.

like image 6
OomPiet Avatar answered Nov 15 '22 16:11

OomPiet


Ok @Dim and @Oompiet's answers are correct but there's a really easy way to do this via the Package Manager Console:

Update-Package -reinstall EntityFramework

That will do it at the Solution level or if you want to do it at the project level just do:

Update-Package -reinstall EntityFramework -p <YouProjectName>
like image 6
Rob Avatar answered Nov 15 '22 16:11

Rob