5
"주어진 인코딩에 잘못된 문자"를 예외 :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;
}
문제가 나타납니다 해당 XAML :
...
<TextBlock>русская надпись</TextBlock>
<TextBlock Text="קח מספר" />
...
을이 구문 분석 중 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)
at System.Windows.Markup.XamlParser._Parse()
at System.Windows.Markup.XamlParser.Parse()
XAML 파일을 UTF-8
아무도 어떻게 이러한 문제없이이 xaml을로드 할 수 있는지 알 수 있습니까? 미리 감사드립니다.
추신 : 문제의 원인을 발견했습니다.
xaml을로드하는 올바른 방법은 XamlReader.Parse 대신 XamlReader.Load 메서드를 사용하는 것입니다. 제 경우에는 다음과 같습니다 :
using (Stream stream = new FileStream(source, FileMode.Open))
{
ParserContext context = new ParserContext()
{
BaseUri = new Uri(Configuration.SkinsFolder)
};
var result = XamlReader.Load(stream, context);
return result;
}
모두에게 감사드립니다!
정말 UTF-8로 인코딩 되었습니까? –
예,이 파일을 BOM과 함께 utf-8로 저장하려고했지만 그 파일은 저장하지 않았습니다. 두 경우 모두 동일한 결과를 얻었습니다. – basilkot
그리고 내가 읽을 문자열을 볼 때 VS 감시자, 그것은 어떤 문제가있다. 모든 문자가 정확합니다. – basilkot