34

In VS 2010, changing <MvcBuildViews>true</MvcBuildViews> in a MVC2 project's .csproj file causes an error if you are using Entity Framework.

Could not load type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider'. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config 129

I want to build views while I'm debugging, and I also want my project to compile!

jonsca
  • 10,218
  • 26
  • 54
  • 62
Alper
  • 1,393
  • 13
  • 16

6 Answers6

60

You can resolve this MVC compile issue by adding the following element to your web.config file:

<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

This will tell the compiler where to find that missing type.

a7drew
  • 7,801
  • 6
  • 38
  • 39
  • 5
    Obvious and logical solution. Thanks. But why is thid behaving like that? Why am I need to add System.Data.Entity.Design namespace to my assembly, it's nothing to do with my code. I Visual Studio's job, it shouldn't be added to my application. – Alper May 13 '10 at 17:01
  • 1
    Does anyone know why this happens? – BrianFinkel Oct 03 '12 at 23:55
  • 8
    Goes in `` - to save anyone else the trouble of figuring that out. Ref http://stackoverflow.com/a/10078384/10245 – Tim Abell Oct 30 '14 at 12:16
5

i had this problem too, and figured out that i had created some entity files (edmx and the like) but had deleted them.

this problem only started happening after i had created these files. on inspection of the application folders, i found that visual studio hadn't actually 'deleted' them off the drive, it had just 'deleted' them out of the project. therefore, when the project was being compiled, it saw this edmx file and decided it would include it. hence the error.

easy fix - permanently delete the entity files off the drive!

benpage
  • 4,418
  • 3
  • 41
  • 39
  • 1
    This ended up being my problem, something had been accidentally dragged and dropped into the wrong folder. – Falkayn Aug 05 '10 at 07:54
  • just figured this out in mine. old replaced edmx was getting picked by the compiler for some @#$@#$ reason. – Brady Moritz Aug 07 '10 at 23:14
  • I think I'd be going back a few steps if I just deleted my .edmx file. It's quite central to my project. – ProfK Feb 14 '12 at 16:29
  • i use linq to sql, not linq to entities. the edmx files were created when i tried to create a linq to entities file. – benpage Mar 03 '12 at 21:50
3

Alternately you can remove the build provider.

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <buildProviders>
      <remove extension=".edmx"/>
    </buildProviders>
  </compilation>
</system.web>
roufamatic
  • 18,187
  • 7
  • 57
  • 86
  • Fails with error: "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level." – Philipp Munin Jun 09 '14 at 20:50
  • @PhilippMunin that error means the config file you are editing is not in the root folder of the IIS application, that usually either means you are editing the wrong one (sub-folders sometimes get config files too) or you haven't configured iis to serve your project as an application. More info on applications: http://technet.microsoft.com/en-us/library/cc771654(v=ws.10).aspx – Tim Abell Oct 30 '14 at 12:04
  • Just wanted to chime in that sometimes this is also due to a web config file in your /obj directory. Just delete the /obj directory and it should work. – Denny Ferrassoli Mar 19 '20 at 18:59
2

This is an complete example web.config

<configuration>
<system.web>
    <customErrors mode="Off"/>
        <compilation debug="true" targetFramework="4.0">
 <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />       
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>
</compilation>
</system.web>
</configuration>
Mark
  • 21
  • 1
0

I had a similar error when setting MvcBuildViews="true" which had to do with the build finding multiple web.configs due to build temp files and simply not liking it.

It's a totally different error, but I have a sneaky suspicion that they could be related...

You can find the original question I had here and then the solution outlined here.

The solution basically gets you to change where the output path is for you builds... so you need to add <BaseIntermediateOutputPath> to your website's csproj file.

E.g.

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...BLAH...
    <BaseIntermediateOutputPath>..\TempBuildOutput</BaseIntermediateOutputPath>
  </PropertyGroup>
  ...A WHOLE LOTTA BLAH...
</Project>

HTHs,
Charles

Community
  • 1
  • 1
Charlino
  • 15,802
  • 3
  • 58
  • 74
0

Not enough rep to add a comment. Wanted to mention that you need to add the 'System.Data.Entity.Design' assembly reference to the root Web.config. I was inadvertently trying to add it to a Web.config in my Views directory. Watch out for this pitfall.

Kyle s
  • 484
  • 5
  • 14
  • 1
    Is this a comment or an answer? If your suggestion fixes the problem faced by the OP, please [edit] this so it's worded as a normal answer and not an attempt to circumvent the rules requiring 50 rep to comment. If it is just a comment posing as an answer, please delete it. This answer is currently in a review queue and could get deleted for violating site rules. – BSMP May 03 '17 at 18:47
  • It is circumventing the rules requiring 50 rep to comment. If someone could add this "answer" to the chosen answer as a comment it would be very useful. Thanks. – Kyle s May 03 '17 at 19:19