Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7437413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:23:47+00:00 2026-05-29T10:23:47+00:00

I am getting XamlParseException when calling XamlReader.Load() in button1_Click(object sender, RoutedEventArgs e) the code

  • 0

I am getting XamlParseException when calling XamlReader.Load() in button1_Click(object sender, RoutedEventArgs e) the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using HTMLConverter;
using System.Windows.Markup;


namespace StackoverflowTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static SqlConnection conn = new SqlConnection("Server=" + @".\SQLEXPRE" +
                                    ";Initial Catalog=Hukuk;" +
                                    "Integrated Security=True;" +
                                    "User ID=;" +
                                    "Password=;");

        public MainWindow()
        {
            InitializeComponent();
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error opening SQL Server connection\n" + ex.Message);
                //Close();
            }

        }

        public static FlowDocument SetRTF(string xamlString)
        {
            StringReader stringReader = new StringReader(xamlString);
            System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);
            return XamlReader.Load(xmlReader) as FlowDocument;
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            SqlCommand commProc = new SqlCommand("SELECT Name, Content from Document where ID=3219", MainWindow.conn);
            string str;
            FlowDocumentReader fdocr = new FlowDocumentReader();
            SqlDataReader dr = commProc.ExecuteReader();
            try
            {
                if (dr.Read())
                {
                    byte[] bt = (byte[])dr["Content"];
                    str = Encoding.Default.GetString(bt);
                    str = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(str, true);
                    fdocr.Document = MainWindow.SetRTF(str);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured while trying to view document\n" + ex.Message);
            }

            dr.Close();
            dr.Dispose();
        }
    }
}

Unfortunately a cannot post the xamlstring I’m trying to pass because it is too big..Is there any other way to show it to you?

And the exception details are here:

System.Windows.Markup.XamlParseException occurred
  Message='Add value to collection of type 'System.Windows.Documents.TableRowGroupCollection' threw an exception.' Line number '1' and line position '28143'.
  Source=PresentationFramework
  LineNumber=1
  LinePosition=28143
  StackTrace:
       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
       at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader)
       at WpfApplication1.MainWindow.SetRTF(String xamlString) in C:\Documents and Settings\nosirovkh\Рабочий стол\посл\WpfApplication1\WpfApplication1\WpfApplication1\MainWindow.xaml.cs:line 69
  InnerException: System.ArgumentNullException
       Message=Value cannot be null.
Parameter name: item
       Source=PresentationFramework
       ParamName=item
       StackTrace:
            at MS.Internal.Documents.TableTextElementCollectionInternal`2.Add(TElementType item)
            at MS.Internal.Documents.ContentElementCollection`2.System.Collections.IList.Add(Object value)
            at System.Windows.Documents.TableRowGroupCollection.System.Collections.IList.Add(Object value)
            at System.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object instance, Object item)
            at MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(Object collection, XamlType collectionType, Object value, XamlType valueXamlType)
       InnerException: 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:23:48+00:00Added an answer on May 29, 2026 at 10:23 am

    It looks like your XAML is probably generated by some program, which is the source of the problem.

    Here is the problem:

    <Table>
      <TableColumn Width="331"/>
      <TableColumn Width="48"/>
      <TableColumn Width="48"/>
      <TableColumn Width="48"/>
      <TableColumn Width="48"/>
      <TableColumn Width="44"/>
      <TableColumn Width="52"/>
      ...
    </Table>
    

    And here is the correct code:

    <Table>
      <Table.Columns>
        <TableColumn Width="331"/>
        <TableColumn Width="48"/>
        <TableColumn Width="48"/>
        <TableColumn Width="48"/>
        <TableColumn Width="48"/>
        <TableColumn Width="44"/>
        <TableColumn Width="52"/>
      </Table.Columns>
      ...
    </Table>
    

    There are 6 tables where this occurs.

    I don’t know what generated this XAML, but this seems like a bad bug. You will either need it to be fixed or fix the XAML file yourself, either by writing a small program to find that kind of thing, or manually with (preferably) Visual Studio.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting Fatal Error while running bin/hadoop namenode -format Using Windows 7 operating system, Under
Getting data from a database table to an object in code has always seemed
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting the above error in following code. How to rectify it. Thanks. Please look
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting output with Java is pretty easy as you can make use of System.out.print
Getting started with python. I am trying to implement positional index using nested dictionary.
I'm trying to bind FontWeight in datagrid to a property in code and getting
Getting a weird error box when using the 64bit version of adobepdf ifilter for
Getting an error with my code found HERE ... Which is a culmination of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.