简体   繁体   English

在visual studio 2013中打开cshtml文件时,对象引用未设置为对象的实例

[英]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: 这是一个相对奇怪的过程,以前对我有用:

  1. Open Visual Studio, open your original project. 打开Visual Studio,打开原始项目。
  2. Open a second copy of visual studio 打开视觉工作室的第二个副本
  3. In second Visual Studio. 在第二个Visual Studio中。 Go to Debug -> Attach to Process and attach to the first visual studio instance. 转到Debug - > Attach to Process并附加到第一个visual studio实例。
  4. Do whatever it was you were doing in the first Visual Studio instance that made the exception occur. 做你在第一个发生异常的Visual Studio实例中做的事情。
  5. Analyze the names of classes/methods in the stack trace to find the buggy extension or plug-in. 分析堆栈跟踪中的类/方法的名称,以找到错误的扩展或插件。
  6. Uninstall offending piece of software. 卸载有问题的软件。

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.

相关问题 MySQL for Visual Studio / Visual Studio 2017数据源向导的问题。 你调用的对象是空的 - Issue with MySQL for Visual Studio / Visual Studio 2017 Datasource Wizard. Object reference not set to an instance of an object Visual Studio 2010 崩溃打开 .cshtml 文件 - Visual Studio 2010 crashes opening .cshtml files 安装 ASP.NET 和 Web Tools 2015 后出现 Visual Studio 错误“未将对象引用设置为对象的实例” - Visual Studio error "Object reference not set to an instance of an object" after install of ASP.NET and Web Tools 2015 转换时未将对象引用设置为对象的实例 - Object reference not set to an instance of an object when converting 你调用的对象是空的。 -Visual Basic(网络) - Object reference not set to an instance of an object. - Visual Basic (Web) 添加WCF服务引用时,“对象引用未设置为对象的实例” - “object reference not set to an instance of an object” when adding a WCF service reference 使用会话对象时,对象引用未设置为对象的实例 - Object reference not set to an instance of an object when using a session object 你调用的对象是空的 - Object reference not set to an instance of an object 对象引用未设置为对象#2的实例 - Object reference not set to an instance of an object #2 你调用的对象是空的 - Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM