简体   繁体   中英

Visual Studio Cannot open cshtml Files

I have a problem, which I cannot solve. I can't open every cshtml-File in a Visual Studio c# mvc project (whatever which project i tried). I get the following error Msg (I try to translate to English):

Object reference not set to an instance to an object

Google says, it may be a NullReferenceExeception. But it has nothing to do with my code, because first I can execute the project successfully and second the error occurs in every project (since today).

I just experienced the same issue. It just came out of nowhere, as you described. I even went through a 2 hour repair. That didn't fix it.

However, a coworker suggested this fix.

Visual Studio 2015 not syntax highlighting razor nor Intellisense

I had the same problem, the only fix so far is by resetting all user data (C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\devenv.exe /ResetUserData).

Now I am able to use the real default editing and I get good syntax highlighting again.

The solution that worked for me was from here

  1. Close VS
  2. Delete the content of %LocalAppData%\\Microsoft\\VisualStudio\\15.0\\ComponentModelCache
  3. Open VS

As suggested by @jamez14, if your are using a different version of Visual Studio, just change 15.0 in the path to the version you have.

I faced the following issue.

ISSUE: All .cshtml were not opening in visual studio 17 community.

REASON: Accendently shutdown laptop by power off button while files were open in visual studio.

I tried all the above solutions but none worked.

Following solution worked for me.

Repaired Visual Studio using Visual Studio Installer .

I had the same problem and the issue turned out that I had disabled Razor Language Service Pack.

To re-enable go to :

Tools > Extensions and Updates > search for Razor Language Package and enable. Close VS and reopen.

在控制台中运行命令: C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\devenv.exe /ResetUserData应该可以解决您的问题,因为它会重置所有用户数据

这对我有用Visual Studio 2015 Broken Razor Intellisense没有重置我的首选项或导致其他副作用。

It is caused by the version of Razor when updates by NuGet and clean the solution. re-build the project and will open without problems.

I had this same thing recently, resetting profiles and the like didn't work, it turned out that I had some dodgy web.config settings:- Removing these lines and re-building the project appeared to solve the issue and I could open cshtml files normally:

<add key="webpages:Version" value="4.0.0.0" />
<add key="webpages:Enabled" value="false" />

I found this solution in a github bug thread that mentions many other potential fixes. It seems to be related to updating your version of ASP.Net on an existing project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM