将 MVC3 项目升级到 VS2012 后的访问违规异常



我使用VS2010开发了一个MVC3网站,效果很好。我最近将我的开发环境升级到VS2012 RTM。我现在无法在不使开发 Web 服务器崩溃的情况下在调试器中运行网站。

WebDev.WebServer40.exe 已停止工作

我在VS2012中看到两个类似的堆栈跟踪之一:

首先,AccessViolationException

mscorlib.dll!System.StringComparer.GetHashCode(object obj) + 0xc bytes  
mscorlib.dll!System.Collections.Hashtable.GetHash(object key) + 0x10 bytes  
mscorlib.dll!System.Collections.Hashtable.InitHash(object key, int hashsize, out uint seed, out uint incr) + 0xf bytes  
mscorlib.dll!System.Collections.Hashtable.Remove(object key) + 0x38 bytes   
System.dll!System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(string name) + 0x2e bytes 
System.Web.dll!System.Web.SessionState.SessionStateItemCollection.Remove(string name) + 0x56 bytes  
System.Web.dll!System.Web.SessionState.HttpSessionStateContainer.Remove(string name) + 0xc bytes    
System.Web.dll!System.Web.HttpSessionStateWrapper.Remove(string name) + 0xf bytes   
Dive7.Site.dll!Dive7.Site.D7WebViewPage<object>.IsAdmin.get() Line 56 + 0x19 bytes  C#

其次,NullReferenceException

mscorlib.dll!System.StringComparer.GetHashCode(object obj) + 0x33 bytes 
mscorlib.dll!System.Collections.Hashtable.GetHash(object key) + 0x10 bytes  
mscorlib.dll!System.Collections.Hashtable.InitHash(object key, int hashsize, out uint seed, out uint incr) + 0xf bytes  
mscorlib.dll!System.Collections.Hashtable.Remove(object key) + 0x38 bytes   
System.dll!System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(string name) + 0x2e bytes 
System.Web.dll!System.Web.SessionState.SessionStateItemCollection.Remove(string name) + 0x56 bytes  
System.Web.dll!System.Web.SessionState.HttpSessionStateContainer.Remove(string name) + 0xc bytes    
System.Web.dll!System.Web.HttpSessionStateWrapper.Remove(string name) + 0xf bytes   
Dive7.Site.dll!Dive7.Site.D7WebViewPage<object>.IsAdmin.get() Line 56 + 0x19 bytes  C#

确切发生的一个似乎是随机的。

据我所知,我所做的只是安装VS2012,重新启动,然后在新版本的VS中打开我的VS2010解决方案,看着它说升级成功,然后按F5

我没主意了。谁能建议可能发生的事情?

请阅读链接 http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815 中的"ASP.NET 安装 MVC 4 中断 ASP.NET MVC 3 RTM 应用程序"部分。按照设置"必需的更新",如果此错误仍然存在,请告诉我。

正如Anand所指出的,当您在VS2012中打开MVC3应用程序时,您必须对其进行一些手动更改,因为VS2012的安装也会导致安装MVC4。这些更改允许并行操作:

Web.config

<appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

然后编辑 MVC 项目的.csproj文件。替换以下行:

<Reference Include="System.Web.WebPages"/> 
<Reference Include="System.Web.Helpers" />

(它们可能看起来像这样):

<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>........Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0AssembliesSystem.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
</Reference>

使用这些行:

<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/> 
<Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

摘自 MVC4 发行说明。

最新更新