31

After installing Visual Studio 2013 and playing around with some of the new features, I noticed I'm unable to open a cshtml file in one of my MVC projects. If I try opening it in the default html editor, I'm receiving the following error

The operation could not be completed

Opening the file in another editor, IE: HTML (Webforms) Editor, opens the file without any issue. So it seems to be an issue with the default Html Editor.

I've followed various suggestions for how to combat this problem from previous versions of VS. If I delete all the solution's ".suo" files, and restart Visual Studio, the error changes to:

Object reference not set to an instance of an object

Once Visual Studio creates a new ".suo" file, the error message reverts back to the previous one.

I've tried doing a repair install on VS2013, however I'm still running into the same issues. Also, running VS in Safe-Mode did not work either. I tried creating a new MVC project, which failed during creation. With any of these errors, the windows event log does not contain any messages.

Has anyone else had this problem?

Tom Stickel
  • 19,633
  • 6
  • 111
  • 113
Brosto
  • 4,445
  • 2
  • 34
  • 51
  • possible duplicate of [Visual Studio popup: "the operation could not be completed"](http://stackoverflow.com/questions/9079466/visual-studio-popup-the-operation-could-not-be-completed) – Nic Sep 28 '15 at 08:26
  • 1
    @Nicholas - While both of the questions have similar symptoms/error messages, the problems are in fact different. The answer to the suggested duplicate involved deleting the .suo file for the project, which did not resolve the issue that I was receiving. The error I was receiving ended up being related to Visual Studio 2013 not handling a web.config setting that previous versions of Visual Studio could handle. – Brosto Sep 28 '15 at 14:53

16 Answers16

35

Just found your question here because it happened to me as well. Here's what I did and hopefully it will fix / help find the problem.

  1. Deleted all .suo
  2. Terminate IIS Express
  3. Close VS2013 and re-open
  4. Open your project and try to start it (F5)
  5. You probably have an error on your web.config file. For me it was an <appSettings> being there twice.
  6. Fixed the web.config file, save and boom, error is gone.

Hope it will also fix your situation.

Dominic St-Pierre
  • 2,429
  • 3
  • 27
  • 35
  • 1
    I followed your steps, but I don't get any error in my web.config, I also checked for duplicate , there were no dupes. Unfortunately, I'm still receiving the error. – Brosto Oct 29 '13 at 22:02
  • 7
    Thanks, I'm pretty sure you only have to check your web.config file. Mine had a merge conflict in it, resulting in this error. – Elger Mensonides Feb 27 '14 at 16:40
  • 4
    An error in the web.config will cause this. For example I had misplaced a element inside of the node instead of at the root which caused this error. Fixing the web.config will allow you to open cshtml files again. – Rush Frisby Mar 13 '14 at 14:01
  • From doing a previous search in the web.config (control + f) I hit shift instead and it printed F at the end of one of the tags. I didn't realize it.. – The Muffin Man Jul 15 '14 at 17:11
  • For me, it was a capitalized "K" in "key" in my section in web.config. Thank you! – Dave Markle Feb 04 '15 at 14:19
25

Found a working solution here (tested with VS2015 Update 1):

https://github.com/aspnet/Tooling/issues/276#issuecomment-166650817

  1. Close VS
  2. Delete the content of %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
  3. Open VS
kabeleced
  • 609
  • 6
  • 9
9

I just figured it out. In my web.config, I had the following in my

  <appSettings>
    <add key="webpages:Version" value="2.0.?.?" />
  </appSettings>

Changing this the value to "3.0.0.0" resolved the issue. I never had a problem with this on VS2010 or VS2012. It seems there is something in the IDE that is not handling this gracefully.

Brosto
  • 4,445
  • 2
  • 34
  • 51
6

That worked for me for VS 2015 (command prompt as Admin):

cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
devenv.exe /resetuserdata
Vlad
  • 57
  • 1
  • 1
5

Like most people here have mentioned, review your web.config file for duplicates. I was in a rush, just copied and pasted appSettings from another solutions without noticing the section existed already in the existing document. Then issue this thread relates to started to surface. I went back and consolidated the appSettings, saved, and the issue ceased to exist.

double <appSettings> conflict

Geovani Martinez
  • 2,053
  • 2
  • 27
  • 32
3

For me this error was resolved by setting the VS 2013 shortcut to "run as administrator".

ErikE
  • 48,881
  • 23
  • 151
  • 196
  • I have this problem on my laptop, but not my desktop. Both machines have pretty much identical Visual Studio configurations. The web.config answer didn't work. I have ReSharper installed, but disabling it didn't solve the problem, so it's probably not related. Running as admin worked for me, but I'd like to have a better fix. Any idea what specifically needs elevated privileges? – Jared Jun 30 '14 at 15:35
  • My only guess: In Windows 7 and up, reading and writing to directories that are outside of the My Documents folder. – ErikE Jun 30 '14 at 23:48
3

Check for errors in your web.config file:

  • duplicate keys (app settings)
  • tags not closed or used multiple times
  • ...
1

It is due to IIS Express not running from Visual Studio when you try to debug the aspx page.

Quick and dirty fix is to right click the your project and choose "Use Visual Studio Development Server" and then again right click and choose back to "Use IIS Express" will fix this problem. This way I will care about all the changes required in configuration file.

Ahmad
  • 11
  • 1
  • This was my problem, except it was related to having no host environment set, I am using LocalIIS, but the Properties->Web->Servers setting was set to ExternalHost, I changed it to the proper one for me and it worked, the "Object reference not set to an instance of an object" error went away. – John Maloney Oct 03 '15 at 23:02
0

I also got this problem after using some Nuget package. The problem was a duplicate of appSettings. I merged them all and it worked.

Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
0

There is also this thread that an MS employee has answered with possible cause:

This is a bug in the debugger. There is a race condition that happens when all of the following are true:

Script debugging is enabled in IE User is debugging IE and another process

The other process stops (hits breakpoint, step operation completes, stops at an exception, etc) at a moment when IE is not running script code

IE starts running script code at roughly the same moment that the user hits F10/F5 in Visual Studio.

The most likely reason for this to happen is that the code from 'setTimeout' is run, but I am not a JScript expert, so I am sure there are other possible reasons as well.

and these workarounds:

  1. If you hit this problem, I believe you could detach the debugger and then re-attach.

-or-

  1. This problem happens when debugging ASP.NET and when script debugging is enabled in IE. If you disable script debugging in IE, or toggle it on and off when switching between debugger server-side and client-side problems, you would be able to work around the issue.

-or-

  1. If your web application is using setTimeout, you may be able to avoid or at least reduce the problem by doing something to ensure that script runs less often. This could mean increasing the timeout value, or this could mean adding conditions around when setTimeout is used.
Community
  • 1
  • 1
Mark
  • 2,926
  • 3
  • 28
  • 31
0

I had error in my web.config file, there was two spaces before <xml> tag. after removing it stopped showing this error.

Techmaster
  • 1,032
  • 2
  • 12
  • 26
0

I had the same error in VS 2015 running on Win 10. Fortunately fixed simply with a reboot. On restart it appears windows applied some updates in the previous session which broke VS somehow.

Dan
  • 1
  • 1
0

I got this error in Visual Studio 2015 but only after I installed ASP.NET 5 RC 1. Installing Visual Studio 2015 Update 1 fixed the problem for me.

Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96
0

What solved my issue is this :

Type %LOCALAPPDATA% in Windows Explorer and go to Microsoft\XX.0 your version of Visual Studio then delete the folder ComponentModelCache

Restart VS and it worked like a charm!

This is due to an update made to GitHub which is reported in their forum

Marc Roussel
  • 459
  • 9
  • 20
0

I was asked by a colleague to look at this problem. I tried all the proposed solutions and nothing worked. Eventually I found that they had done a project Update from svn and they had a conflict and ignored it. In one of the config files I found the conflict marked ".yours". I corrected this and all now loads without error.

Fred
  • 5,663
  • 4
  • 45
  • 74
0

In my case, the problem was due to my web.config's app settings include pointing to a file that doesn't exist:

<appSettings configSource="App_Config\MISSPELT-FILENAME.config" />
Andy Holt
  • 572
  • 2
  • 9