C# 加载正在引发System.Windows.Markup.XamlParseException
以下情况可能有什么问题:C# 加载正在引发System.Windows.Markup.XamlParseException,c#,xaml,load,xamlreader,C#,Xaml,Load,Xamlreader,以下情况可能有什么问题: <Run FontWeight=\"Bold\" Foreground=\"#FF0000FF\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\"><Run.TextDecorations><TextDecoration Location=\"Underline\" /></Run.TextDec
<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>
046/98 5802007513\r\n
虽然XamlReader.Load可以很好地加载类似的其他文件,但这会引发以下异常:
“类型的第一次机会例外
中出现“System.Windows.Markup.XamlParseException”
PresentationFramework.dll
其他信息:给定编码中的无效字符。行
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);
}
}
}
}
使用系统;
使用System.IO;
使用系统文本;
使用System.Windows.Markup;
名称空间XamlTesting
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串str=“046/98 5802007513\r”;
streams=newmemoryStream(ascienceoding.Default.GetBytes(str));
尝试
{
var temp=XamlReader.负载;
}
捕获(例外情况除外)
{
控制台写入线(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);
}
}
static void Main(字符串[]args)
{
字符串str=“046/98 5802007513\r”;
尝试
{
var temp=XamlReader.Parse(str);
}
捕获(例外情况除外)
{
控制台写入线(ex);
}
}
我认为这与双引号无关,因为双引号是反斜杠!它不起作用。请尝试从“98 5802007513”中删除空格