question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NRE when loading FlowDocument

See original GitHub issue

Following code throws a NRE in dotnet 7 When loading xaml that has beein previously saved, you will get a NRE . It has something to do with the Run.TextDecoration.

We ran into this issue because of a help tool we created that fails to load help pages since we upgraded to dot net 7.

       [TestMethod]
       public void ErrorOnXamlSerializeDeserialize()
        {
            string xaml = "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" >" +
                          "<Paragraph><Run>" +
                          "<Run.TextDecorations><TextDecorationCollection xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><TextDecoration PenThicknessUnit=\"FontRecommended\" Location=\"Underline\"><TextDecoration.Pen><Pen Brush=\"#FF00FFFF\" Thickness=\"2\" /></TextDecoration.Pen></TextDecoration></TextDecorationCollection></Run.TextDecorations>" +
                          "xxx</Run></Paragraph></Section>";

 

            MemoryStream mems = new MemoryStream();
            mems.Write(Encoding.UTF8.GetBytes(xaml));
            mems.Position = 0;

            FlowDocument doc = new FlowDocument();

 

            TextRange all = new TextRange(doc.ContentStart, doc.ContentEnd);
            all.Load(mems, DataFormats.Xaml);

 

            MemoryStream saveStream = new MemoryStream();
            all = new TextRange(doc.ContentStart, doc.ContentEnd);
            all.Save(saveStream, DataFormats.XamlPackage);

 

            saveStream.Position = 0;
            all = new TextRange(doc.ContentStart, doc.ContentEnd);
            all.Load(saveStream, DataFormats.XamlPackage);

 

        }

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
IAmTheCSharkcommented, Dec 29, 2022

Now some of our customers starting to report this issue on .net 4.8 versions So my guess is this might be some recent change that is distributed via windows update. @lindexi fyi

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forcing a FlowDocument to Load?
I'm in the process of trying to print out a FlowDocument that is being viewed by the user. I wrote a routine to...
Read more >
Flow Document Overview - WPF .NET Framework
A flow document is designed to "reflow content" depending on window size, device resolution, and other environment variables.
Read more >
How do I load a FlowDocument XAML content from outside ...
This FAQ explains the topic "How do I load a FlowDocument XAML content from outside the application directory?"
Read more >
FlowDocument Class (System.Windows.Documents)
Gets a value indicating whether this element has been initialized, either by being loaded as Extensible Application Markup Language (XAML), or by explicitly ......
Read more >
Creating a FlowDocument from Code-behind
So far, we've been creating our FlowDocument's directly in XAML. ... FlowDocument doc = new FlowDocument(); Paragraph p = new Paragraph(new Run("Hello, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found