Socket reading inputstream: No mapping for the Unicode character exists in the target multi-byte code page.

Unanswered Socket reading inputstream: No mapping for the Unicode character exists in the target multi-byte code page.

  • lunedì 16 aprile 2012 09:12
     
      Contiene codice
            async private void WaitForData(StreamSocket socket)
            {
                var dr = new DataReader(socket.InputStream);
                dr.InputStreamOptions = InputStreamOptions.Partial;
               //byte bytes[];
               
                
                var stringHeader = await dr.LoadAsync(8000);
    
                if (stringHeader == 0)
                {
                    return;
                }
    
              
                uint numStrBytes = dr.UnconsumedBufferLength;
                /*
                byte[] bytes = new byte[numStrBytes];// Encoding.UTF8.GetBytes(basicTicket);
                char[] charout = new char[numStrBytes*32];
            
                dr.ReadBytes(bytes);
                StringBuilder sb = new StringBuilder();
    
                byte[] zoyt = new byte[numStrBytes * 4];
                zoyt=Encoding.UTF8.GetBytes(bytes.ToString());
    
                for (int i = 0; i < numStrBytes; i++)
                {
    
                }
                Convert.ToBase64CharArray(bytes, 0, (int)numStrBytes, charout, 0);
                string msg = charout.ToString();
                */
                
                string msg = dr.ReadString(numStrBytes);
    
                
                WaitForData(socket);
            }

    "An exception of type 'System.ArgumentOutOfRangeException' occurred in Application10.exe but was not handled in user code

    WinRT information: No mapping for the Unicode character exists in the target multi-byte code page."

    What should i do to basically read the input into a string? I am not connected to a normal web server but i receive text from the remote server.

Tutte le risposte

  • mercoledì 18 aprile 2012 16:07
    Moderatore
     
     

    There are a lot of reasons this could happen, it's not a Metro-style application issue.  Try a web search:

    http://tinyurl.com/6w82nb8

    If nothing seems to work, come back here.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator

  • martedì 15 gennaio 2013 08:05
     
      Contiene codice

    I was experiencing this very same issue. Unfortunately the data in my app was being read from an SSL socket so I could not use a packet dump to see what the offending character might be. The good news is that the exception causes the buffer to remain unread so you can use this code to see what's in there causing the exception:

    try
    {
        data = dr.ReadString(length);
    }
    catch (ArgumentOutOfRangeException e)
    {
        byte[] rawdata = new byte[length];
        dr.ReadBytes(rawdata);
        Debug.WriteLine(Encoding.Unicode.GetString(rawdata, 0, rawdata.Length));
    }
    

    You may need to set a breakpoint on the Debug.Writeline. In my case the data (returned from a third party app) turned out to be garbage so no codepage was able to transcode the string to something I could read. For most situations though I think this may help find the cause of the problem.

    Markus.