UART bytes to string issue

I have a simple UART routine not returning the correct string. Im sending “AAABBBCCC” and can clearly see the bytes in the b array when I inspect it but when I do the …GetChars it return “~~”

        private void gprs_DataReceivedEvent(object state)
    {
        int read, pos;
            int NumberOfBytesToRead = gprs_serial.BytesToRead;

            if (NumberOfBytesToRead > 0)
            {
                byte[] b = new byte[NumberOfBytesToRead];
                read = gprs_serial.Read(b, 0, b.Length); //
                string word= new String(Encoding.UTF8.GetChars(b, 0, b.Length)); //always return ~~
            }

    }

Does it work correctly if you just use an array and convert it

why not utf8.getstring?

Thinks i found the issue but not sure how to resolve. What does Encoding.UTF8.GetChars do for non utf8 chars?

This is the packet it receives…
``b = new Byte[] { 126, 0, 11, 129, 0, 4, 54, 2, 65, 65, 66, 66, 67, 67, 182 };

string dd = new String(Encoding.UTF8.GetChars(b, 0, b.Length));//this appears to fail if non ascii characters found?

It doesn’t work, that is known. But what do you think it should return?

thanks Gus, ill do some custom decoding to allow it to work…thought it would ignore the non utf8 chars but guess not.

You say you are sending “AAABBBCCC” and get back ~~ sounds more like you have the wrong baud rate as “AAABBBCCC” is valid UTF8

thanks, the isue has been resolved by removing not valid utf8 data from byte array