小编bas*_*kot的帖子

XamlReader.Parse抛出"给定编码中的无效字符"

我有以下代码的问题:

using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
    var content = reader.ReadToEnd();
    ParserContext context = new ParserContext()
    {
        BaseUri = new Uri(Configuration.SkinsFolder)
        //,XmlLang = "utf-8" // I have tried with this parameter and without it
    };
    var result = XamlReader.Parse(content, context);
    return result;
}
Run Code Online (Sandbox Code Playgroud)

相应的xaml,出现问题:

...
<TextBlock>??????? ???????</TextBlock>
<TextBlock Text="?? ????" />
...
Run Code Online (Sandbox Code Playgroud)

在解析这个xaml期间,我得到了异常:

Invalid character in the given encoding. Line 76, position 167.
   at System.Windows.Markup.XamlReaderHelper.RethrowAsParseException(String keyString, Int32 lineNumber, Int32 linePosition, Exception innerException)
   at System.Windows.Markup.XamlReaderHelper.Read(XamlNode& xamlNode)
   at System.Windows.Markup.XamlParser.ReadXaml(Boolean singleRecordMode) …
Run Code Online (Sandbox Code Playgroud)

.net wpf xaml

5
推荐指数
1
解决办法
2403
查看次数

标签 统计

.net ×1

wpf ×1

xaml ×1