.net - XamlReader.Parse throws the "Invalid character in the given encoding" -


i have problem following code:

using (streamreader reader = new streamreader(stream, encoding.utf8)) {     var content = reader.readtoend();     parsercontext context = new parsercontext()     {         baseuri = new uri(configuration.skinsfolder)         //,xmllang = "utf-8" // have tried parameter , without     };     var result = xamlreader.parse(content, context);     return result; } 

the corresponding xaml, problem appears:

... <textblock>русская надпись</textblock> <textblock text="קח מספר" /> ... 

during parsing xaml exception:

invalid character in given encoding. line 76, position 167.    @ system.windows.markup.xamlreaderhelper.rethrowasparseexception(string keystring, int32 linenumber, int32 lineposition, exception innerexception)    @ system.windows.markup.xamlreaderhelper.read(xamlnode& xamlnode)    @ system.windows.markup.xamlparser.readxaml(boolean singlerecordmode)    @ system.windows.markup.xamlparser._parse()    @ system.windows.markup.xamlparser.parse() 

xaml file saved utf-8

anybody knows how can load xaml without such problems? in advance!

ps: ok, have found source of problem.

the correct way load xaml use xamlreader.load method instead of xamlreader.parse. in case seems as:

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; } 

thanks all!

i've had same problem german umlaut characters. think there's bug in .net framework. try use function instead of xamlreader.parse(content, context):

public static object parse(string xamltext, parsercontext parsercontext) {   return system.windows.markup.xamlreader.load((stream) new memorystream(encoding.utf8.getbytes(xamltext)), parsercontext); } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -