Entity Framework references missing between debug and release builds

There must be something I don’t understand about the difference between debug builds and releases and using references. I am using Entity Framework 6 to connect to a database that was previously configured. I can successfully create and run a project while it is in debug mode. If I change it to release mode, I immediately get build errors indicating that the namespaces and types that were there can no longer be found. I checked and as far as I can tell, both the .Net 4.5 target framework that I saw might have been a problem for some other people. I see no difference in what is indicated in the links in my solution explorer.

I use visual studio 2013. I am happy to provide any code, but I do not know what would be most relevant.

Some of the errors I get are:

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 recommendations that can be provided.

+7
c # console-application entity-framework-6
source share
4 answers

Switching to release mode and then reinstalling the entity structure in the problematic project fixes this problem in my case.

+6
source share

To solve this problem, I used @ OomPiet . For me there were the following steps:

  • Switch to debug mode
  • Recover Solution - Create Successful
  • Switch to release mode
  • Recover Solution - Build Failed
  • In Solution Explorer click on the project that will not be created (my project was unit test)
  • Right Click Project> Manage NuGet Packages
  • Make sure Installed packages selected.
  • Choose EntityFramework
  • Click Uninstall and close the dialog box.
  • Click Solution in Solution Explorer
  • Right Click> Manage NuGet Packages for Solution
  • Make sure Installed packages selected.
  • Choose EntityFramework
  • Click Manage
  • Verify that the project causing the problem is checked
  • Click OK and close the dialog after installation.
  • Click Select Solution in Solution Explorer
  • Right-click Restore Solution

Now I can switch between Debug and Release without compilation failure. Hope this helps

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

+8
source share

The answers Ok @Dim and @Oompiet are correct, but there is a very simple way to do this through the package manager console:

 Update-Package -reinstall EntityFramework 

This will be done at the solution level or if you want to do it at the project level, simply do:

 Update-Package -reinstall EntityFramework -p <YouProjectName> 
+6
source share

In debug mode, there is additional information with assemblies (pdb file).

This allows the application to receive additional dependencies.

In release mode, there are no such things, so you must refer to assemblies.

Performing step 10-18 of @Dib will solve the problem.

0
source share

All Articles