What is this error in ASP.NET MVC 3 RTM Project? - asp.net-mvc-3

I Create new Project ASP.NET MVC 3 RTM and Replace References for
using ASP.NET MVC 3 Source code
but When I run project again, get this exception:
[A]System.Web.WebPages.Razor.Configuration.HostSection
cannot be cast to
[B]System.Web.WebPages.Razor.Configuration.HostSection.
Type A originates from
'System.Web.WebPages.Razor,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' in
the context 'Default' at location
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Type B originates from
'System.Web.WebPages.Razor,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' in the context
'Default' at location
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary
ASP.NET
Files\root\2505c7ee\369315c5\assembly\dl3\f7bae428\d03eeed8_85bbcb01\System.Web.WebPages.Razor.DLL'.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Source Error:
Line 106: internal static RazorWebSectionGroup GetRazorSection(string virtualPath) {
Line 107: // Get the individual sections (we can only use GetSection in medium trust) and then reconstruct the section group
Line 108: return new RazorWebSectionGroup() {
Line 109: Host = (HostSection)WebConfigurationManager.GetSection(HostSection.SectionName, virtualPath),
Line 110: Pages = (RazorPagesSection)WebConfigurationManager.GetSection(RazorPagesSection.SectionName, virtualPath)
Source File:
E:\GreenTour\webpages\src\System.Web.WebPages.Razor\WebRazorHostFactory.cs
Line: 108

This error means that part of your application is being compiled using your own copy of the source code as a reference while at runtime its finding the reference assemblies in the GAC. Make sure you remove all references to the GACed version of MVC 3 assemblies. This includes a number of things in your web.config files that use this public key token: 31bf3856ad364e35.

I just came across the same problem whilst upgrading my app, the problem was in the web.config file located in the views directory, I blindly copied this over from the old app (my bad).
My solution , create a new MVC 4 app and copy the web.config from the views directory to your app thats having the problem.
Hope this helps

Although the above thread was useful. I could not get things working until I created a 'dummy' 'basic' MVC 4 application and then compared the web.configs to find any changes.

I fixed this not by removing all references to assemblies with the public key of 31bf3856ad364e35 as this covers a lot of irrelevant assemblies.
Instead it should be fixed by updating all configuration references
System.Web.Mvc to 4
System.Web.WebPages to 2
System.Web.WebPages.Razor to 2
Be sure to update all the web.configs, including the ones in View directories.

Related

reset password MVC core 2.1 template with identity scaffold cannot find _Layoutlogin .cshtml

I am getting an error with my asp.net core 2.1 MVC project template. It looks like _Layoutlogin .cshtml is not able find. File is there in the shared folder and the only thing is that in the error message before .chmtl there is space at the end. This is happening after scaffolding idenitity
An unhandled exception occurred while processing the request.
InvalidOperationException: The layout view '~/Views/Shared/_Layoutlogin .cshtml' could not be located. The following locations were searched:
~/Views/Shared/_Layoutlogin .cshtml
Microsoft.AspNetCore.Mvc.Razor.RazorView.GetLayoutPage(ViewContext context, string executingFilePath, string layoutPath)
I suspect you have a typo some place if you check _Layoutlogin .cshtml there is a space in their so if in fact your file is _Layoutlogin.cshtml its not going to find it.

Intermittent "Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter'" Error

I am working on a project that includes an ASP.NET WebAPI component.
Intermittently, I get the following error:
Could not load type
'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from
assembly 'System.Net.Http.Formatting, Version=5.2.3.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
with the source error pointing to my GlobalConfiguration.Configure() call:
Line 35: {
Line 36: AreaRegistration.RegisterAllAreas();
Line 37: GlobalConfiguration.Configure(WebApiConfig.Register); //<-- error here
Line 38: FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Line 39: RouteConfig.RegisterRoutes(RouteTable.Routes);
In my register, I am doing the following to return JSON by default:
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes
.FirstOrDefault(t => t.MediaType == "application/xml");
if (appXmlType != null)
{
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
(not sure of the source, but found somewhere on this site as a way to return JSON by default, unless the caller asks for something else)
I'd like to continue to return JSON as the default content type going forward.
The project includes two other (non WebAPI) websites (that are MVC5), which hit the WebAPI site.
Here's the interesting thing:
This DOES NOT happen when the application is deployed (to Azure)
This only happens occasionally
Typically, I run one of the MVC5 sites in the debugger and see this issue
If I navigate directly to the WebAPI site after the above, I'll get the "Yellow Screen of Death" with the error as per above
Sometimes, even after a cold reboot, this error will NOT appear, other times it will
What I currently do to work around the problem:
If I run the WebAPI site in the debugger, if the error is present, it will fixed itself
After running in the debugger (per above), I can relaunch an MVC5 site in the debugger and the issue goes away
Just to repeat, this DOES NOT happen ever when the application is deployed to Azure.
I have multiple developers working on this project, and we all run into the same error at some stage.
I am referencing the following Nuget packages:
Microsoft.AspNet.WebApi (version 5.2.3)
Microsoft.AspNet.WebApi.Client (version 5.2.3)
Microsoft.AspNet.WebApi.Core (version 5.2.3)
Microsoft.AspNet.WebApi.Owin (version 5.2.2)
Microsoft.AspNet.WebApi.WebHost (version 5.2.3)
If I look inside the *.csproj file, I have a reference to the following:
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
I've checked the bin folder of the website, and all the assemblies inside it have the correct version as per the above list (including System.Net.Http.Formatting.dll).
Also note that, during debugging and development, each of the three websites are run under Local IIS (constraints of external resources force us to do this), so I have:
http://localhost/site1
http://localhost/site2
http://localhost/api
It's becoming cumbersome to get into a debugging session, to get this error, to then stop debugging, launch the API site under the debugger, and to then switch back to what I was doing at the start.
Not sure where else to go to track down what is happening here. Any ideas?
Update - 26 July 2016
Still have this happening. Since posting the question, have updated the WebAPI to run in its own Application Pool, but that doesn't seem to have made a difference.
Uninstalled Web API 2 NuGet package
Installed Web API 2 NuGet package again.
I think you are going about it wrong. Try setting JSON as your default media formatter like this:
// first clear all formatters
config.Formatters.Clear();
// Since JSON is the first added,
// it will be the "default" if no Accept header present
config.Formatters.Add(new JsonMediaTypeFormatter());
// You can choose not to add these back if you never want to use them,
// up to you.
config.Formatters.Add(new XmlMediaTypeFormatter());
config.Formatters.Add(new FormUrlEncodedMediaTypeFormatter());
I had added what was possibly an incorrect version of System.Net.Http.Formatting to my Global Assembly Cache (GAC) and started getting
Could not load type
'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly
'System.Net.Http.Formatting
errors in my Webservice. After removing this System.Net.Http.Formatting dll from GAC my webservice started working again.
when you build looks for any warning that talks about conflict. Double-clicking on the warnings injects the compatible versions in the section of web.config. This obviously can be done manually also.

the type exists in both asp.net

I just integreated blogengine.net into my exting webapplication(not a website)
To do this I have converted all blog engine pages into webapplication page. set namespace references according to the application folders
I have built solution successfully.But when I run main application following error occured.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0433: The type 'MyStore.App_Code.Controls.PostPager' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\6332283b\32bb0d6a\App_Code.afjt0bia.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\6332283b\32bb0d6a\assembly\dl3\faca6d87\a3e83425_6ad8cd01\MyStore.DLL'
I have checked all the namespace refferences but I haven't found any duplicate refferences.
please help me to get out of this.
Move your code files out of the App_Code folder and put them in a Classes folder.

Custom Membership - Error in Web Site Administration Tool (Type is not resolved for member'')

I had to customize the class MembershipProvider for the user validation is done by email.
But when you open the Asp.net Web Site Administration Tool, the "Security" tab the following error:
There is a problem with your selected data store. This can be caused
by an invalid server name or credentials, or by insufficient
permission. It can also be caused by the role manager feature not
being enabled. Click the button below to be redirected to a page where
you can choose a new data store.
The following message may help in diagnosing the problem: Type is not
resolved for member
'System.Data.Entity.ModelConfiguration.ModelValidationException,EntityFramework,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Because the code is great and not to pollute the topic, I put on github.
Code:
https://gist.github.com/1146084
While I am still new to MVC 3 and EF 4.1, try adding a line in your web.config for EntityFramework assembly. It seems like I had this problem as well with my setup. I can't remember the exact line, but it's something like (I will look it up when I get home):
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Stuck with ASPNETCOMPILER : error ASPRUNTIME: Type is not resolved for member 'FluentNHibernate.Cfg.FluentConfigurationException,FluentNHibernate

I'm using Team City for continual integration, for a .Net 4 ASP MVC 3 application.
On my dev machine I can build and run my application, but on the build sever I'm getting the following error:
ASPNETCOMPILER : error ASPRUNTIME: Type is not resolved for member 'FluentNHibernate.Cfg.FluentConfigurationException,FluentNHibernate, Version=1.2.0.712, Culture=neutral, PublicKeyToken=8aa435e3cb308880'
The FluentNHibernate assembly is referenced by the project and I've even added the assembly to the web.config assemblies section, but I still get the error.
What can I do to diagnose the problem?
To sum up Rob White's comment, the problem is certain code running in WebActivator.PreApplicationStartMethod. The fix is to move that code into Application_Start in the Global.asax.
The WebActivator.PreApplicationStartMethod is an assembly attribute for loading code extremely early in the build process. Phil Haack give a good description. The attribute is supposed to be used for registering build providers and other things that are used later in the build process. As such, the ASPNET compiler has to load and run this code in order to begin compilation of views.
I got this particular error on appharbor after I added some code to my IoC (StructureMap) startup code that accessed a resource (MongoDB). Since this resource wasn't accessible to the appharbor build machine, it threw all kinds of errors.
The takeaway is that PreApplicationStartMethod is meant for pre-application-start things, like building, not initializing the application. If you're doing app initialization things, do it in Global.asax Application_Start. I know the default StructureMap NuGet package for MVC4 uses the attribute instead of Global. There might be other packages that lead you to that same mistake.

Resources