Attempt by 'System.Web.Mvc.PreApplicationStartCode.Start()' to critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed - asp.net-mvc-4

My application was working fine and after I did some upgrades I am getting this error.
Server Error in '/' Application.
Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed.
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.
Exception Details: System.MethodAccessException: Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055
I cannot remember the updates I did. Is there a way to fix this?

I think the issue has been solved, but if not, use this package from Nuget:
Install-Package Microsoft.AspNet.Mvc -Version 5.0.0
I have wasted a day for this error but this single line has done the work for me

tried . . . Install-Package Microsoft.AspNet.Mvc -Version 5.0.0
and. . . Install-Package -Id Microsoft.AspNet.WebHelpers
both with no success, finally had to update all packages via nuget. . worked!!
http://www.3dbuzz.com/forum/threads/202082-ASP-net-MVC-Error-before-application-start
If you're using visual studio open the nuget packages windows and run
Update-Package, this will update all your dll to the last version. If
it still not work, see this page:
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

I got this error when deploying a site where Mvc had been upgraded from 4 to 5 but I had not updated web.config.
Changing from this:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
to this:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
solved the problem for me.

For me also same error occured.
It was fixed by installing the NuGet package
Install-Package -Id Microsoft.AspNet.WebHelpers

I had a similar problem, and solved it by based on the article Updating Razor 2.0 to 3.0 with Asp.net MVC by by Anthony Fassett
The following block of code was missing from my Web.Config:
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

In my case it was an incompatibility issue. I had theses pacakges:
Microsoft.AspNet.Mvc version 4.x
Microsoft.AspNet.Razor and Microsoft.AspNet.WebPages, version 3.x
I suppose that upgrading Mvc to 5.x would have worked, but I needed to keep Mvc 4.x, so i had to downgrade Razor and Mvc to 2.x. To do so, you just have to install the older version, like this:
Install-package Microsoft.AspNet.WebPages -version 2.0.30506
Install-Package Microsoft.AspNet.Razor -Version 2.0.30506
After downgrading these packages, the first error disappeared, but there was still another error related to a problem in web.config. I had to change the binding redirect for Razor:
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" ... />
<!--bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /-->
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
I don't know why, but the binding redirect wasn't updated by the Nuget installation, which should have done it.

There are multiple solutions for this problem:
Follow the tutorial on upgrading your asp.net solution
Don't forget to remove the Microsoft-Web-Helpers dll and install the nuget package Microsoft.AspNet.WebHelpers
Then, make sure you have upgraded all your nuget Packages (use "Upgrade-Package") and check your dll's in web.config.
The error is probably an action in an old DLL, when you are converting your project.

In my case, a nuget installation had changed my Web.Config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
newVersion="1.1.0.0"** should be newVersion="5.1.0.0"

Right Click to Project -> Manage Nuget Packages for solution than find
Microsoft.AspNet.Mvc and Microsoft.Net.Compilers update latest versions

I solved my problem by applying the "Install-Package Microsoft.AspNet.Mvc" command.
After that I solved my project with Web API.

I received this error when I upgraded a NuGet package - 'Microsoft.AspNet.Web Pages' version 3.2.3. I am using VS2012, starting a new vanilla 'ASP.NET MVC 4 Web Application' with template 'Internet Application' using Windows Authentication or Windows Azure authentication.
Perhaps the update is not compatible with other components, and these other components must also be upgraded. Other answers suggest updating Microsoft.AspNet.Mvc, Microsoft.Net.Compilers, and/or Microsoft.AspNet.WebHelpers.

I am working on ASP.NET Web API project and fetch same problem after adding following nuget CacheCow.Server.EntityTagStore.SqlServer
It solved installing this one
Install-Package Microsoft.AspNet.Mvc

Install-Package -Id Microsoft.AspNet.WebHelpers
Install-Package Microsoft.AspNet.Mvc -Version 5.0.0
This worked for me

Related

Assembly binding redirect in .NET Core

How do I do assembly binding redirect in .NET Core?
I found this question asked a few time with no solutions offered. The situation is trivial. I have a package refering to assembly A in version 10. I want to use assembly A in version 12. In a standard .NET it works perfectly with this:
<dependentAssembly>
<assemblyIdentity name="Microsoft.AnalysisServices.AdomdClient" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-15.1.52.23" newVersion="12.0.0.0" />
</dependentAssembly>
With help of Rena, adding
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
to the project file helped. The .config file got autogenerated with the correct binding redirect.

VS2012 NuGet update causing cryptic warnings on build

The recent Visual Studio 2012 update seems to have broke something in my build. I think it has to do with last week's nuget update.
NuGet package restore started.
All packages are already installed and there is nothing to restore.
NuGet package restore finished.
1>------ Rebuild All started: Project: Project1, Configuration: Debug Any CPU ------
1> Consider app.config remapping of assembly "Microsoft.Data.OData, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "5.2.0.0" [] to Version "5.6.0.0" [C:\Users\avianbc\Desktop\Project1\packages\Microsoft.Data.OData.5.6.0\lib\net40\Microsoft.Data.OData.dll] to solve conflict and get rid of warning.
1> Consider app.config remapping of assembly "Microsoft.Data.Edm, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "5.2.0.0" [] to Version "5.6.0.0" [C:\Users\avianbc\Desktop\Project1\packages\Microsoft.Data.Edm.5.6.0\lib\net40\Microsoft.Data.Edm.dll] to solve conflict and get rid of warning.
1> Consider app.config remapping of assembly "System.Spatial, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "5.2.0.0" [] to Version "5.6.0.0" [C:\Users\avianbc\Desktop\Project1\packages\System.Spatial.5.6.0\lib\net40\System.Spatial.dll] to solve conflict and get rid of warning.
1>c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.
1> Project1 -> C:\Users\avianbc\Desktop\Project1\Project1\bin\Project1.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
How could I resolve these warnings? I've had all kinda of weird side effects in my application since they have appeared such as: inconsistent model binding (related to the Edm assembly?).
As the message indicates you can fix these warning by mapping the assembly version 5.2 to version 5.6. You do this by editing the assemblyBinding of your config file. In this case, add the following XML:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.6.0.0" />
</dependentAssembly>
I'm not sure why you think this is cryptic, it's quite clear. You have more than one version of those packages installed (5.2 and 5.6) Some of your components are referencing 5.2 and some 5.6, and this is causing the warning. It's suggesting that you alias 5.2 to 5.6 so that the assemblies referencing 5.2 will use 5.6 instead.
This is probably no the best approach though, unless you have no control over those assemblies. You should probably just uninstall the 5.2 packages, and then update the nuget references to the 5.6 version and rebuild.

After upgrading to webgrease 1.5.1.25624 from nuget, System.IO.FileLoadException is coming

I am asp.net death page, this is coming after i upgraded webgrease and bootstrap for mvc4 using nuget.
Server Error in '/' Application.
Could not load file or assembly 'WebGrease' or one of its
dependencies. Strong name signature could not be verified. The
assembly may have been tampered with, or it was delay signed but not
fully signed with the correct private key. (Exception from HRESULT:
0x80131045) 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.
Exception Details: System.IO.FileLoadException: Could not load file
or assembly 'WebGrease' or one of its dependencies. Strong name
signature could not be verified. The assembly may have been tampered
with, or it was delay signed but not fully signed with the correct
private key. (Exception from HRESULT: 0x80131045)
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to
determine why the assembly 'WebGrease' could not be loaded.
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.18045
Force uninstall the package using Package Manager Console
uninstall-package -f WebGrease
then install the previous version 1.3.0 using the following command
install-package WebGrease -Version 1.3.0
Open your Web.config file and replace below dependency under runtime tag
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
I had to add the following code in web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
...
I had the same error. It was happened because nuget updated WebGrease dll but didn't update a web.config file (especial version of used dll).
So I changed next line in my web.config:
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
to
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
Number of version (1.6.5135.21930) I took from dll properties.
After this everything works correct.
We’re aware of an error in the assembly’s strong name signature and so we’re actively working to release an updated version as soon as possible. For now, we have unlisted the WebGrease 1.5.1 package from nuget.org.
Try this: Check if the above dll's are in GAC. If so, in your custom app bin folder check if the above dll's are present if so remove them from your reference.

Error Running Code Analysis in VS2012

I receive the following two errors when I try to compile my MVC4 web project:
CA0058 Error Running Code Analysis CA0058 : The referenced assembly 'DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' could not be found. This assembly is required for analysis and was referenced by: C:\Users\bflynn\Visual Studio Sites\mnp\bin\mnp.dll, C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\Microsoft.Web.WebPages.OAuth.dll. [Errors and Warnings] (Global)
and
CA0001 Error Running Code Analysis CA0001 : The following error was encountered while reading module 'Microsoft.Web.WebPages.OAuth': Assembly reference cannot be resolved: DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246. [Errors and Warnings] (Global)
I recently added the DotNetOpenAuth.AspNet package to the application, and it seems tied to that. I have Cleaned, Rebuilt, Open/Closed the program, Uninstalled/Re-installed the package, yet the errors persists.
I just ran into this too.
Don't upgrade DOA to 4.1
It looks like the aspnet dll has a specific version referenced. Altough it's .nuspec file says 4.0+ is ok...
Solution:
Uninstall-Package -Force each DotNetOpenAuth package (core /aspnet /oauth/openid etc)
Install-Package DotNetOpenAuth.AspNet -Version 4.0.4.12182
I used this to resolve the issue:
1. Uninstall-Package Microsoft.AspNet.WebPages.OAuth –RemoveDependencies
2. Install-Package DotNetOpenAuth.AspNet -Version 4.0.4.12182
3. Install-Package Microsoft.AspNet.WebPages.OAuth
I ran into the same issue the other day and reported it http://aspnetwebstack.codeplex.com/workitem/443
Problem was reported on 21. september 2012. (http://aspnetwebstack.codeplex.com/workitem/443)
It was closed on 5. june 2013 with message:
The next version of MVC will not have a dependency on DotNetOpenAuth. Use the recommended workarounds below.
So I used the workaround https://stackoverflow.com/a/12847018/1016682
Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API
See Yao's answer. The only solution I found that actually works for this.
I had the same issue. Though the code analysis issue got fixed, the web application wouldn't run because of the following error.
Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It turned that the web.config was not cleaned as part of the uninstall.
I had to remove the following dependentAssembly from web.config under the runtime/assemblyBinding section.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
</dependentAssembly>
</assemblyBinding>
</runtime>
The details can be read in http://www.bigcode.net/2013/07/error-running-code-analysis-in-vs2012.html

Cache provider for NHibernate 2.0.1.GA using ASP.NET Cache object

I have migrated my application from NHibernate 1.2.1 to NHibernate 2.0.1. Now i am geting the error "Version Conflict error while compiling". It shows that application still using the NHibernate V1 but i have changed the Version by deleteing the old dll and added the new dll in application refference.
The only thing i have not changes is NHibernate.Caches.SysCache.SysCacheProvider and it is still pointing to the old version "1.0.1".
How could i migrate this, please help me
-Gunasekaran sambandhan
NHibernate.Caches is part of the contrib package. You need to download the latest version and update your assembly.
U can use an Assemmbly redirect provided in your application config file or the webconfig file like this
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="AA95F207798DFDB4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.0.2001" newVersion="2.1.0.1002"/>
</dependentAssembly>
</assemblyBinding>
</runtime>