file io - WinRT No mapping for the Unicode character exists in the target multi-byte code page -


i trying read file in windows 8 store app. here fragment of code use achieve this:

        if(file != null)         {             var stream = await file.openasync(fileaccessmode.read);             var size = stream.size;             using(var inputstream = stream.getinputstreamat(0))             {                 datareader datareader = new datareader(inputstream);                 uint numbytes = await datareader.loadasync((uint)size);                 string text = datareader.readstring(numbytes);             }         } 

however, exeption thrown @ line:

string text = datareader.readstring(numbytes); 

exeption message:

no mapping unicode character exists in target multi-byte code page. 

how this?

i managed read file correctly using similar approach suggested dude:

        if(file != null)         {             ibuffer buffer = await fileio.readbufferasync(file);             datareader reader = datareader.frombuffer(buffer);             byte[] filecontent = new byte[reader.unconsumedbufferlength];             reader.readbytes(filecontent);             string text = encoding.utf8.getstring(filecontent, 0, filecontent.length);         } 

can please elaborate, why initial approach didn't work?


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -