System.InvalidOperationException in html-xaml in case of Table.Columns XAML tag present


  1. Start convertHtml solution
  2. Select XAML to HTML tab
  3. Use the following XAML:
    "<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Table> <Table.Columns> <TableColumn Width="100" /> </Table.Columns> </Table> </FlowDocument>"
  1. Click "Convert!"
"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

Additional information: Token StartAttribute in state Content would result in an invalid XML document."

Source of the problem: Table.Columns tag is special, and the parser goes ahead and tries to summarize all the upcoming TableColumn tags, so it can add the summation to an attribute of the just opened HTML TABLE. In the beginning of looking ahead, it encounters the new line character, and calls "htmlWriter.WriteEndElement();" for that. This whacks out the internal state of htmlWriter from the opened TABLE tag to a Content state. That's when the code tries to add the width attribute, but the HTML writer already finished writing of the TABLE opening tag, the attribute cannot be added as a content.