为什么我的 MVC 项目在安装 WebMatrix 2 Beta 后在生产服务器上抛出异常?
在我的开发计算机上安装 WebMatrix 2 Beta 后,在该计算机上编译并部署到生产服务器的 MVC 项目将开始抛出 FileNotFoundException
寻找 System.Web.WebPages
。
"...System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.WebPages,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified. File name: 'System.Web.WebPages, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'..."
我在谷歌上找不到任何可以帮助解决这个问题的东西,所以我在这里为遇到这种情况的其他人询问并回答这个问题。导致这个问题的是一系列相当模糊的情况。
如果您有一个相当旧的 MVC 项目,并且已在各个版本上进行升级,则可能有一个对 System.Web.WebPages
的未版本化项目引用。
<Reference Include="System.Web.WebPages" />
只要您的项目在编译时找到的版本与部署时可用的版本相匹配,这种方法就可以正常工作。
安装 WebMatrix 2 Beta 将添加此 DLL 的新版本。您的 MVC 项目将开始拉取 v2.0.0.0 进行编译。当您转移到未安装 WebMatrix 2 Beta 的系统时,它将无法找到 v2 并会抛出上述异常。
After installing WebMatrix 2 Beta on my development machine, an MVC project compiled on that machine and deployed to a production server will start throwing a FileNotFoundException
looking for System.Web.WebPages
.
"...System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.WebPages,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified. File name: 'System.Web.WebPages, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'..."
I couldn't find anything on Google to help with this, so I am asking and answering this here for anyone else that runs into this situation. It is a fairly obscure set of circumstances that lead up to this problem.
If you have a fairly old MVC project that you have been upgrading over the various releases, you may have an unversioned project reference to System.Web.WebPages
.
<Reference Include="System.Web.WebPages" />
This works fine as long as the version your project finds where compiled matches the version available where it is deployed.
Installing WebMatrix 2 Beta will add a new version of this DLL. Your MVC project will start pulling v2.0.0.0 for compilation. When you move to a system without WebMatrix 2 Beta installed, it will not be able to find v2 and will throw the above exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我启动了一个新的 MVC 3 项目,并注意到有几个参考文献在新项目中完全合格,并且在问题项目中更通用。
如果您切换到这些项目引用而不是通用引用 (
),您将确保该项目是使用预期版本的 DLL 进行编译的而不是选择系统上可用的最新版本。I spun up a new MVC 3 project and noticed that there are a couple references that are fully qualified in the new project and much more generic in the problem project.
If you switch to these project references instead of the generic ones (
<Reference Include="..." />
), you will make sure the project is compiled with the expected version of the DLL rather than picking up the latest one available on the system.