XamlReader.Load 正在投掷 System.Windows.Markup.XamlParseException

XamlReader.Load is throwing System.Windows.Markup.XamlParseException

以下可能有什么问题:

<Run FontWeight=\"Bold\" Foreground=\"#FF0000FF\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\"><Run.TextDecorations><TextDecoration Location=\"Underline\" /></Run.TextDecorations>046/98 5802007513 \r</Run>

虽然 XamlReader.Load 可以很好地加载类似的其他内容,但会抛出以下异常:

"A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: Invalid character in the given encoding. Line 1, position 233."

复制问题的代码:

using System;
using System.IO;
using System.Text;
using System.Windows.Markup;

namespace XamlTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = "<Run FontWeight=\"Bold\" Foreground=\"#FF0000FF\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\"><Run.TextDecorations><TextDecoration Location=\"Underline\" /></Run.TextDecorations>046/98 5802007513 \r</Run>";
            Stream s = new MemoryStream(ASCIIEncoding.Default.GetBytes(str));
            try
            {
                var temp = XamlReader.Load(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}

使用 "(双引号)代替 \,如下所示

字符串 str = @"http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xml:space=""preserve"">046/98 5802007513 \r";

使用相同的输入调用 XamlReader.Parse 而不是 XamlReader.Load 不会抛出异常 "XamlParseException",但是我不知道有什么区别以及它是如何工作的。

    static void Main(string[] args)
    {
        String str = "<Run FontWeight=\"Bold\" Foreground=\"#FF0000FF\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\"><Run.TextDecorations><TextDecoration Location=\"Underline\" /></Run.TextDecorations>046/98 5802007513 \r</Run>";

        try
        {
            var temp = XamlReader.Parse(str);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }