BryanP
BryanP

Reputation: 330

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.

Upvotes: 9

Views: 5942

Answers (4)

Yan Brunet
Yan Brunet

Reputation: 4897

In Debug mode, there is extra information with the assemblies (the pdb file).

This allows the application to fetch the extra dependencies.

In release mode, there is no such things, thus the assemblies must be referenced.

Doing step 10 to 18 from @Dib will solve the issue.

Upvotes: 0

Dib
Dib

Reputation: 2093

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.

Upvotes: 10

Rob
Rob

Reputation: 10248

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>

Upvotes: 7

OomPiet
OomPiet

Reputation: 76

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

Upvotes: 6

Related Questions