[英]Object reference not set to an instance of an object when opening cshtml files in visual studio 2013
When I try to open .cshtml files in Visual Studio 2013 I get this error: 当我尝试在Visual Studio 2013中打开.cshtml文件时,我收到此错误:
Object reference not set to an instance of an object
I have tried the solution given here but it did not work. 我试过这里给出的解决方案,但它没有用。 Here is my appsettings section in the
web.config
: 这是我在
web.config
appsettings部分:
<appSettings>
<add key="Port" value="25" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
i do not think that the problem is about this particular project, because all my other MVC projects have same problem. 我不认为问题是关于这个特定的项目,因为我所有的其他MVC项目都有同样的问题。
I had exact same issue in Visual Studio 2015. 我在Visual Studio 2015中遇到了完全相同的问题。
I solved it by deleting all files in %LocalAppData%\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache
我通过删除
%LocalAppData%\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache
所有文件解决了这个问题
(the 14.0
folder with be different depending on VS version installed I think. (根据安装的VS版本,
14.0
文件夹有所不同我认为。
Try creating a new project and add a cshtml file. 尝试创建一个新项目并添加一个cshtml文件。 Do not make any other changes and do not use any templates you created.
不要进行任何其他更改,也不要使用您创建的任何模板。 If the issue still occurs when you attempt to open this file, something is wrong with your system.
如果在尝试打开此文件时问题仍然存在,则系统出现问题。
In this case you could attempt to get more information from VS by enabling the log. 在这种情况下,您可以尝试通过启用日志从VS获取更多信息。 Detailed link to enable log
启用日志的详细链接
Simple example 简单的例子
Devenv /log
Devenv / log
Here's a relatively weird process that has worked for me before: 这是一个相对奇怪的过程,以前对我有用:
If trying to open an asp.net mvc 4 project in your Visual Studio 2013 then review the web.config edit <appSettings>
as following 如果尝试在Visual Studio 2013中打开asp.net mvc 4项目,请查看web.config编辑
<appSettings>
如下
<appSettings>
<add key="webpages:Version" <add value="3.0.0.0"/>
<add key="webpages:Enabled" <add value="false"/>
<add key="PreserveLoginUrl" <add value="true"/>
<add key="ClientValidationEnabled" <add value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" <add value="true"/>
</ appSettings>
Hope this helps :) 希望这可以帮助 :)
Do you have any extensions installed? 你有安装的扩展吗? Maybe one of them is throwing this error.
也许其中一个人正在抛出这个错误。
Can you try starting vs.net in SafeMode and check if the problem still occurs? 你能尝试在SafeMode中启动vs.net并检查问题是否仍然存在? If yes, try to disable your extensions one by one until it disappears.
如果是,请尝试逐个禁用您的扩展程序,直到它消失。
devenv.exe /SafeMode
devenv.exe / SafeMode
Other solution, double check that your entire web.config
is valid (not only the appSettings section). 其他解决方案,仔细检查您的整个
web.config
是否有效(不仅仅是appSettings部分)。 It cannot contains duplicate, invalid child, not well formed XML... 它不能包含重复的,无效的子,没有格式良好的XML ...
It might be a problem with the version of Javascript you are using. 这可能是您正在使用的Javascript版本的问题。 I had a similar problem where i just uninstalled and reinstalled the latest nuget packages.
我有一个类似的问题,我刚刚卸载并重新安装了最新的nuget包。 Then i made sure the right versions listed in web.config.
然后我确保web.config中列出了正确的版本。
I had this funny error, this worked for me then.. 我有这个有趣的错误,这对我有用..
try 'Unload project' and reloading again by right clicking on project name in solution explorer 尝试“卸载项目”并通过右键单击解决方案资源管理器中的项目名称重新加载
In my visual studio 2015 resolved by deleting all files in the% LocalAppData% \\ Microsoft \\ VisualStudio \\ 14.0 \\ ComponentModelCache 在我的visual studio 2015中通过删除%LocalAppData%\\ Microsoft \\ VisualStudio \\ 14.0 \\ ComponentModelCache中的所有文件解决
Thanks... 谢谢...
Basically, make sure your web.config isn't corrupt. 基本上,请确保您的web.config没有损坏。
I got this after inserting "&" instead of "amp;"
插入“&”代替
"amp;"
后我得到了这个 into an app setting. 进入应用程序设置。
Try this; 尝试这个; In my visual studio 2015 resolved by deleting all files in the% LocalAppData% \\ Microsoft \\ VisualStudio \\ 14.0 \\ ComponentModelCache it's work.
在我的visual studio 2015中通过删除%LocalAppData%\\ Microsoft \\ VisualStudio \\ 14.0 \\ ComponentModelCache中的所有文件解决了它的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.