Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not reformat the document" in ASP.NET, VS2008

I'm in an ASP.NET UserControl. When I type Control-K, Control-D to reformat all the markup, I get a series of messages from VS 2008:

"Could not reformat the document. The original format was restored."

"Could not complete the action."

"The operation could not be completed. The parameter is incorrect."

Anybody know what causes this?

Edit: OK, that is just...weird.

The problem is here:

<asp:TableCell>
  <asp:Button Text="Cancel" runat="server" ID="lnkCancel" CssClass="CellSingleItem" />
</asp:TableCell>

Somehow that asp:Button line is causing the problem. But if I delete any individual attribute, the formatting works. Or if I add a new attribute, the formatting works. Or if I change the tag to be non-self-closing, it works. But if I undo and leave it as-is, it doesn't work.

All I can figure is that this is some sort of really obscure, bizarre bug.

like image 454
Ryan Lundy Avatar asked Sep 16 '08 18:09

Ryan Lundy


6 Answers

I had an unwanted semi-colon. But you may have quote ('), double quote ("), semi-colon (;) or any special character.

So, editing my answer with more details and a screenshot because it still very active.

enter image description here

Go to that line by double clicking the error and search for the extra (unwanted) quote ('), double quote ("), semi-colon (;) or any special character. Remove it because it is causing the error.

like image 72
Prince Tyagi Avatar answered Oct 27 '22 22:10

Prince Tyagi


My problem was an extra ". Look carefully the html.

like image 24
Sterling Diaz Avatar answered Oct 27 '22 22:10

Sterling Diaz


There's probably some malformed markup somewhere in your document. Have you tried it on a fresh document?

like image 9
John Sheehan Avatar answered Nov 08 '22 08:11

John Sheehan


Did get the problem today.

My solution: Restart Visual Studio

like image 5
Olle89 Avatar answered Nov 08 '22 07:11

Olle89


Usually this sort of behavior is caused by invalid code. It may only be invalid HTML causing it which would still allow the program to be compiled.

For example, if tags are mismatched like this the IDE cannot reformat it.

<div><h1>My Title</div></h1

Check your warnings to see if there are any entries pointing towards mismatched or unclosed tags.

like image 2
palehorse Avatar answered Nov 08 '22 08:11

palehorse


For me, it's usually as issue with whitespace. To fix it, I open Find and Replace (CTRL+H), set Look in to "Current Document", check Use and select "Regular expressions". For Find what I enter ":b|\n" (minus quotes), and for Replace with I enter a single space. Then I click Replace All.

The steps above will replace all whitespace—including line breaks—with a single space, and the next time you format the document, you shouldn't get any errors. That is assuming you don't have malformed HTML.

like image 2
jordanbtucker Avatar answered Nov 08 '22 06:11

jordanbtucker