|Inconsistent length calculation in projection snapshot.|
I have no flipping idea what that is supposed to mean which is why this error is going into my “Application errors hall of shame”. Therefore as usual, you click OK, you know – because you are presented with such a huge list of alternatives and you try again. Well trying again gave me this error instead:
|Attempted TextBuffer edit operation while another edit is in progress.|
I understand this error a little clearer, but honestly it doesn’t matter because it is a symptom of the overall problem. Long story short, “Something broke”. This message in particular is just saying that you already tried to copy, cut or paste something already and that operation didn’t complete so you cannot start a new one. Hence the TextBuffer is in use, you cannot edit it while in use.
At this point I thought Visual Studio was broken. I should have known better because other CSHTML files were just fine. I am going to break this down in what to do and what not to do:
Don’t do these things because they are unnecessary in this situation and won’t help
- Don’t reinstall Visual Studio
- Don’t repair Visual Studio
- Don’t run “devenv.exe /resetsettings”
- Don’t delete your solutions “.vs” hidden folder
- Don’t delete the contents of your ComponentModelCache folder: “%appdatalocal%/Microsoft/VisualStudio/14.0/” – This is assuming VS2015
- You can and should install Visual Studio updates, but it won’t help with you with this problem
Do this instead
Hopefully this solves your problem, as all weird problems I cannot predict that we are having the same problem. Anyhow – all you have to do is inspect your problem *.cshtml file for something that looks like the following snippet below. This is just an example of actual code I was working with. Please understand this is a subsection and this code isn’t supposed to make sense.
|Please click the image to view it clearly, it is a little large.|
What happened? My file was corrupted during a keyboard operation. I am not certain, but I believe the corruption occurred when I attempted to do a rename operation on a variable on the page using F2. This is a bug in Visual Studio for sure because the MVC view editor is very buggy. It is constantly crashing Visual Studio for me. Please draw your attention to the lines that start with a hashtag “#” – I didn’t put those there. VS put them there when the rename operation failed horribly and corrupted the file. To make matters worse, I lost the bottom half of my file. Thank goodness for source control, I was able to recover everything just fine.
#line 72 "C:Devthis_is_the_path_to_this_viewExpanded.cshtml"
__o = val;
#line 73 "C:Devthis_is_the_path_to_this_viewExpanded.cshtml"
Therefore in order to fix this, you have to get rid of all of the corrupted syntax and lines that I am pointing out above. Just be aware that you might have lost the bottom half of your file too. You might want to get forced latest from source control or proceed at your own risk after fixing your file. If the syntax highlighting comes back and you can copy, cut and paste freely again – then the file is fixed.