MvcBuildViews true with Entity Framework in ASP.NET MVC 2 - asp.net

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!

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.

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!

Alternately you can remove the build provider.
<system.web>
<compilation debug="true" targetFramework="4.0">
<buildProviders>
<remove extension=".edmx"/>
</buildProviders>
</compilation>
</system.web>

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>

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

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.

Related

Should I remove unused bits out of Web.config?

My current WebMatrix web site is very basic - it simply shows mostly static context, photos, and contains a few links. Many things are referenced in Web.config that I don't use in this site, such as support for SqlServerCe. Should I remove those things references, for performance purposes, or does it not matter to leave them in? I don't think I'm using the OAuth stuff, either (not deliberately, anyway), and I don't know about "WebGrease," etc.
I also wonder about removing StarterSite.sdf
You can delete almost everything from it. Mine looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation targetFramework="4.5">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Your assemblies can differ or miss.

ASP.NET Charting Control not working on production server

I have an application that relies heavily on charting and currently the charts will work in the ASP.Net Development Server, but when I try to publish out to my server (Win 2008 Server R2, IIS 7), the charts do not show up.
Using Firebug, I can see that the call to ChartImg.axd returns a 404, and all I get is a blank image holder in IE, or nothing in Firefox. I've searched for about 3 or 4 hours so far, and have tried just about everything recommended, but nothing seems to be working.
I would like to use memory/HttpImageHandler, instead of the ImageLocation configuration.
My Web.Config
<appSettings>
<!--<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />-->
<add key="ChartImageHandler" value="storage=memory;timeout=20;deleteAfterServicing=false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<customErrors mode="Off"/>
</system.web>
Does anyone have any ideas where I'm going wrong to keep this from working on my server?
I found the answer to my problem, but I believe that my problem stemmed specifically from how my code runs.
Once I set privateImages=false under appSettings for my ChartImageHandler, my images came up with no problem, using ImageLocation with file storage or HttpHandler with memory storage.
I looked at the listing here and realized that my code has NONE of the following:
Authentication
SessionID
AnonymousID
so the implicit default setting of privateImages=true was keeping me from downloading my images. When I set privateImages=false I had no problems and the charts worked correctly. I set my application to use Windows Authentication, and set privateImages=true and my charts are now being generated with either the Image Location setting or the HttpHandler setting.
Hopefully this is helpful. I know I spent a long time digging around and got nowhere.
This configuration work for me. You need to use memory as storage.
< add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;timeout=20;"/>
It seems like security/permission issue. Are you saving charts to local folder, then assign write permission for IIS user and/or network services users for that folder.
Install the Microsoft Chart Controls on your webserver or try this:
ASP.Net Chart Control On Shared Hosting Environment
Also check that the HttpHandler is registered in system.webServer in your web.config when running under IIS 7.
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
try this: change Version=4.0.0.0 to Version=3.5.0.0
try this it was resolved in case of web.config runtime error
<pre>
<add key="ChartImageHandler" value="storage=memory;timeout=20;deleteAfterServicing=true;Url=~\temp\"
/>

"The name 'HTML' does not exist in the current context" in MVC 3 Views

I´m starting to use "MVC 3" but I´m facing some little problems. In my Views, when I code something like this:
#if(Request.IsAuthenticated) {
<text>Welcome <b>#Context.User.Identity.Name</b>!
[ #Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
#:[ #Html.ActionLink("Log On", "LogOn", "Account") ]
}
The objects like #Request and #Html is indicating an error: The name 'HTML' does not exist in the current context.
The same occurs with #Context, #ViewBag, #Layout, #Url and others.
See:
But the code is correctly compiled with no errors. The problem is that I cannot use the Intellisense with theses objects in the Views. Is it normal? (I don´t think so). What could be happening?
I have reinstalled the MVC 3 framework but the same still occurs.
Note: this is a new project from scratch, not a MVC 2 migration. This occurs both with Razor engine and ASPX.
This is the Web.Config in the Views folder:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
Thanks!
You could try:
Close the View with the false errors.
(Steps 2-5 are sometimes optional) Close Visual Studio
Delete the bin and obj folders in all the Projects in the Solution.
Reopen the same Solution
Rebuild the Solution
Open a different View then the one causing the errors
Close that View, hopefully you didn't see any of the similar errors in this View
Reopen the View that gave you problems earlier
I have solved this issue with the old, good, wise Microsoft default solution: reinstall all the things again.
Uninstall and Reinstall the Visual Studio 2010 and MVC 3 Framework.
Clean your solution and Under references.
Then set the follow property:
System.Web.MVC file to Copy Local = True.
All I had to do was close all views that were open in the editor and rebuild.
What worked for me was closing Visual Studio, deleting the user option files (both solution and project level), then relaunching Visual Studio.
I'm using dotnet core sdk 2.2 and Visual Studio Professional 2019.
This was caused by Visual Studio mangling code.
Code was pasted into the razor view. Visual Studio would attempt but then fail to auto-format it. Part of the failure resulted in deleting code.
Pressing ctrl+z reverted the formatting but kept the pasted code. The razor compilation errors were then fixed (The name 'Html' does not exist in the current context)
Disable format on paste (see https://stackoverflow.com/a/28053865/1462295 ) under Tools -> Options -> Text Editor -> HTML -> Advanced
For me this just seemed to be the fact that I had compiler warnings. Code would still compile and run ok but it was not until I fixed all the build warnings that my Intellisense starting working.
I tried to remove the project that is still in trouble from solution and add it back again, after which the problem had been gone.
Set the property of System.Web.MVC,Copy Local = True
In my case my Packages folder was missing including MVC and Razor so I have updated packages in packages.config, reopened the view and it worked.
All you need to do is Restart Visual Studio and check.
You could try some following point:
Close the View with the false errors.
Close visual studio.
open project again.
clean your solution
Rebuild your solution.
hopefully you will not get any of the similar errors now.
If you still have same problem. than Please check following steps.
Make sure you have web.config file inside view folder. Becuase MVC has two web.config. one for solution and other one for project.
Your web.config file will seems like this which is inside views folder.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Your Project Name" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
It worked for me. and hope for you also.
Close Visual Studio => Delete the obj and bin folders located in your project => Start Visual Studio
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
solution for this problem in web.config
I experienced this on ASP.NET MVC 4 as well, after uninstalling EntityFramework from my packages list.
I had to remove this section
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, ....
that's left on the Web.config file... at the least it removed the errors from the errors list
Apologies for the necro post.
Selecting "Build | Rebuild Solution" corrected this issue for me in Visual Studio 2015. In my case, the warnings occurred after renaming the primary namespace of a project. A rebuild set everything straight.
I'm using ASP .net core. Solved mine by upgrading Microsoft.AspNetCore.Mvc from 1.1.2 to 1.1.3.
For me, I just restarted my Visual Studios and everything got fixed.
Maybe I am a bit late to answer this question but this easy fix helped me:
Right click the file > Exclude from project.
Right click the file > Include in project.
I had this same issue in MVC 4. None of these solutions worked for me. Instead, in Windows, I went into Control Panel -> Uninstall a program. Select Microsoft ASP.NET MVC 4 in the program list. Click 'Uninstall.' A 'Microsoft ASP.NET MVC 4 Setup' wizard will display. Click 'Repair.'

ASP.NET Chart: What's wrong with my web.config. I can't display a chart

I just created a web page having a barebone chart with a few data points to test. On localhost, the chart is displayed as expected with no problem. But when I deployed to my webhost I got a 500 - Internal Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Here's the web.config uploaded by Visual Studio. Could you tell me what's missing or wrong in this web.config. The appSettings look suspicious with a dir in C:, but how do I change it? Thanks.
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
</appSettings>
<system.webServer>
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
</system.web>
</configuration>
try this link
http://asifhuddani.wordpress.com/2010/10/07/chart-control-asp-net-4-0-and-iis-7-problem/
and then delete dir=c:\TempImageFiles\; from web.config
I had the same problem, namely a 500 server error adding in the same section. Two changes resolved the 500 serve error.
replaced "add path="ChartImg.axd" verb="GET,HEAD with add path="ChartImg.axd" verb="GET,HEAD,POST".
Added line after system.webServer tag:
[validation validateIntegratedModeConfiguration="false"/]
I had to replace < with [, otherwise the preview did not show the tag.
Problem is the temporary directory. It could be because:
The directory no exists,
The user has no permission to the directory,
You are pointing to the wrong directory, or
when you move your programs form a local PC to a server you are no longer pointing to a local file, you are pointing to a URL
Solutions:
If you are using a web server, the easy and lazy solution is create a directory named temp where the aspx is located. In the same directory and give the users permission to modify.
If you are using a local PC you can use memory instead of file. No use this in the web server because is to heave for many users, but use:
<add key="ChartImageHandler" value="Storage=memory;Timeout=20;"/>
If you are using a web server, the best option is use a url instead of a file like this:
<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/temp" />
You can use ~ / . or http://…
To Add permission to the ISS user, could be your user pool, windows user or any user as you used before. If you use Windows authentication, then you should grant permission to the user named “Domain Users”. Some people add permission to the user everybody. This permission should include “Modify”

How to reference assemblies that are in the GAC

In Visual Studio 2005, you need to add a new registry setting in order to see it in the Add Ref dialog box.
BUT
can you add a reference an assemble that are in the GAC in the web.config file?
i.e.
<system.web>
<compilation>
<assemblies>
<add assembly="MNissen.DataControls, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e21df62f5c740a13" />
<add assembly="Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e21df62f5c740a13" />
<add assembly="Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e21df62f5c740a13" />
<add assembly="Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e21df62f5c740a13" />
<add assembly="Microsoft.ApplicationBlocks.ExceptionManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e21df62f5c740a13" />
</assemblies>
</compilation>
</system.web>
You need to add a <assemblies> tag section in web.config.
Check this article for more info - http://msdn.microsoft.com/en-us/library/bfyb45k1.aspx
Greg
I've created a sexy visual studio extension that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Regards...
Muse Extensions

Resources