以下内容可能有什么问题:
<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 可以很好地加载类似的其他内容,但这会引发以下异常:
“在 PresentationFramework.dll 中发生了‘System.Windows.Markup.XamlParseException’类型的第一次机会异常
附加信息:给定编码中的无效字符。第 1 行,位置 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);
}
}
}
}