奇怪的错误升级ASP.NET MVC 4至5 [英] Weird Error Upgrading ASP.NET MVC from 4 to 5

查看:113
本文介绍了奇怪的错误升级ASP.NET MVC 4至5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从MVC 4转换我的项目MVC 5(和.Net 4到.NET 4.5.2,它是变化的真正驱动力。)

当我跑我的网页之一,我得到这个错误(由我为便于阅读加空格)


  

[A] System.Web.WebPages.Razor.Configuration.HostSection不能投
  为[B] System.Web.WebPages.Razor.Configuration.HostSection。


  
  

键入从'System.Web.WebPages.Razor,版本= 1.0.0.0一个起源,
  文化=中性公钥= 31bf3856ad364e35'的背景下,
  默认的位置
  'C:\\windows\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Web.WebPages.Razor\\v4.0_1.0.0.0__31bf3856ad364e35\\System.Web.WebPages.Razor.dll'.


  
  

B型从'System.Web.WebPages.Razor,版本= 3.0.0.0起源,
  文化=中性公钥= 31bf3856ad364e35'的背景下,
  默认的位置
  C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\临时ASP.NET
  Files\\studentportal3g\\2204bad2\\aece9b3b\\assembly\\dl3\\ad80387c\\91adbf51_fc73d101\\System.Web.WebPages.Razor.dll'.


当我第一次看到这虽然方便啊!与其说:)

我已经过每一个项目,并确保它的版本升级到具有3.0.0.0版本System.Web.WebPages.Razor.dll的MVC 5。

清洁重建,仍然得到错误。没问题,我会删除缓存的临时文件。

清洁重建,仍然得到这个问题。我回去,手动检查System.Web.WebPages.Razor.dll的每个版本,在具有对它的引用每个项目的引用。我检查我的文件夹中复制我的DLL进行手动对它们的引用,它不存在。

如果我的解决方案不'包含DLL或DLL的引用的副本,我已经手动删除缓存文件夹C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\临时ASP.NET


  

文件\\ studentportal3g ...


在哪里老坏DLL是从哪里来的?如何解决这个问题?我如何prevent它再次发生?

谢谢,

埃里克 -


解决方案

Visual Studio是一个伟大的工具,但它并不总是做出正确的选择,当涉及到升级的依赖,也不支持在每个提供可能的选择的MSBuild。当你发现自己处于困境,如这个,你应手动检查和(如有必要)修改 .csproj的文件,以解决这个问题。

问题是不是你的文件中的GAC存在或尚未通过的NuGet安装,这个问题很有可能是您的项目文件中的一个仍与旧版本的 System.Web.WebPages.Razor 版本 1.0.0.0 ,你需要找到它的所有引用并将其更改为 3.0.0.0 相应。


  1. 在Solution Explorer中的项目节点上单击鼠标右键,点击卸载项目

  2. 再次右键单击该项目节点,并单击编辑< PROJECTNAME方式>的.csproj

  3. 的引用文件搜索 System.Web.WebPages.Razor 和更新版本和 HintPath 相应(如下所示)。确保 HintPath 您实际使用指向现有的文件。

  4. 重复这些步骤解决方案中的所有相关项目(以及任何在不属于解决方案的一部分的DLL)。

旧参考

 <参考包括=System.Web.WebPages.Razor,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35,的ProcessorArchitecture = MSIL>
    <私人和GT;真< /私人和GT;
    <HintPath>..\\packages\\Microsoft.AspNet.WebPages.1.0.20105.408\\lib\
et40\\System.Web.WebPages.Razor.dll</HintPath>
&LT; /参考和GT;

更新参考

 &lt;参考包括=System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31bf3856ad364e35,的ProcessorArchitecture = MSIL&GT;
  &LT;私人和GT;真&LT; /私人和GT;
  <HintPath>..\\packages\\Microsoft.AspNet.WebPages.3.0.0\\lib\
et45\\System.Web.WebPages.Razor.dll</HintPath>
&LT; /参考和GT;

您也应该通过web.config文件,以确保它不会引用该组件的任何旧版本。


  

注意:如果上述说明不能解决您的问题,这个问题可能是您的解决方案之外。很可能是被某个引用旧版本的文件的第三方库。如果是这样,你可以尝试获得DLL的更新版本。


您可能也想看看这个问题

I'm converting my project from MVC 4 to MVC 5 (and .Net 4 to .Net 4.5.2, which is the real driver of the changes.)

When I run one of my pages I get this error (blank space added by me for easier reading)

[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=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\studentportal3g\2204bad2\aece9b3b\assembly\dl3\ad80387c\91adbf51_fc73d101\System.Web.WebPages.Razor.dll'.

When I first saw this is though, Ah easy! Not so much :)

I've gone over every project and made sure it's version is upgraded to MVC 5 which has the 3.0.0.0 version of System.Web.WebPages.Razor.dll.

Clean rebuild, still get the error. No problem , I'll delete the cached temp files.

Clean rebuild, still get the problem. I go back, manually check each version of System.Web.WebPages.Razor.dll, in the references of each project that has a reference to it. I check my folder where I copy dlls to make references to them manually, it's not there.

If my solution doesn't' contain a copy of the DLL or a reference to the DLL, and I've manually deleted the cache folders in 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET

Files\studentportal3g...

Where is the old bad dll coming from? How do I fix this error? How do I prevent it happening again?

Thanks,

Eric-

解决方案

Visual Studio is a great tool, but it doesn't always make the right choices when it comes to upgrading dependencies, nor does it support every possible option available in MSBuild. Whenever you find yourself in a bind such as this you should manually review and (if necessary) edit your .csproj file in order to resolve it.

The problem isn't that your file exists in the GAC or that it has not been installed by NuGet, the issue is most likely that one of your project files still has a reference to the old version of System.Web.WebPages.Razor version 1.0.0.0, and you need to find all references to it and change them to 3.0.0.0 accordingly.

  1. Right-click on your project node in Solution Explorer and click Unload Project.
  2. Right-click the project node again and click Edit <projectName>.csproj.
  3. Search the file for references to System.Web.WebPages.Razor and update the version and the HintPath accordingly (as shown below). Make sure the HintPath you use actually points to an existing file.
  4. Repeat these steps for all dependent projects in the solution (and any that are in DLLs that are not part of the solution).

Old Reference

<Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Private>True</Private>        
    <HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

Updated Reference

<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

You should also go through the web.config file to ensure that it is not referencing any old versions of this assembly.

NOTE: If the above instructions don't solve your issue, the issue likely is outside of your solution. Most likely there is a 3rd party library that is referencing the old version of the file somewhere. If so, you could attempt to get an updated version of the DLL.

You may also want to check out this question.

这篇关于奇怪的错误升级ASP.NET MVC 4至5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆