Inconsistent length calculation in projection snapshot

Viewed 1748

In Visual Studio 2017 something unexpected happened when I was working. I was editing razor view (nothing special, just normal editing - I've copy pasted small chunk of text) and all the sudden I've got this message:

enter image description here

I've tried to restart visual studio, delete suo file, delete my temporary folder... now I can not work inside this particular view. If I try to change anything in this .cshtml I got message above or this message:

enter image description here

What is this? I don't recall seeing this in previous versions of visual studio. How to avoid this and proceed with work?

3 Answers

I got this in VS 2019 and just needed to restart VS.

I found an issue and they claim the issue was fixed in the new version. So I updated, but the issue still occurred, maybe because it was triggered in the old version.

Clean/rebuild didn't work. What I ended up doing after updating (I don't know if all steps are necessary, but this worked for me):

  • Copy the contents of the old file (make edits if necessary, I didn't have valid .cshtml at the time and I didn't want to run into the same error again)
  • Created a new file and paste the contents in there
  • Delete the old file
  • Commit code
  • Rename old file to new name
  • Commit code again

Then it was solved

I too ran in to this today with Visual Studio 2019. The editor was showing a bunch of what looked like metadata inserted in the middle of the file. The garbage text even ended up getting checked in to my repo when I didn't notice it.

Any attempt to "fix" (i.e. delete) the garbage data would result in the OP's errors or other strange errors. Closing VS and reloading didn't help.

What finally did work though was to copy the file contents (which oddly enough didn't include the garbage data when copied to the clipboard from VS) to a new file in Notepad++, then close VS, save the file from Notepad++ over the top of the original file, then reload the project. After that everything was fine.

It seems like something goes haywire and it gets it's buffers crossed or something. Once it happens, VS is unable to deal with the file any more and the only alternative seems to be editing it outside of VS.

Related