See the following function for writing data to the sending Buffer Queue.
/// <Summary> /// Sending cache area /// </Summary> /// <Param name = "content"> </param> /// <Param name = "bufferoffset"> </param> /// <Param name = "senderbuffer"> </param> Private Void Writesendbuffer (String Content, Int Bufferoffset, Byte [] Sendbuffer ){ Int Bytelength = Encoding. utf8.getbytecount (content ); If (Bytelength <= Sendbuffer. Length ){ Byte [] Sendbytes = Encoding. utf8.getbytes (content ); // Encoding. utf8.getbytes (content, 0, bytelength, senderbuffer, bufferoffset) will be incorrect at noon ); // Replacing the above with an array copy will solve the problem. Array. Copy (sendbytes, 0 , Sendbuffer, bufferoffset, bytelength ); // Copy to Data Packet Buffer }}
Note that the getbytes of utf8 does not have any Chinese Character in the content. If it is ASCII, it is also a problem. However, if unioncode is used and there is a Chinese character, the array is out of bounds directly. The error message is:
The index and Count must reference the position in the string.
It is estimated that this is a bug in. net. It must be because the Chinese bytes have not been properly processed. Is there an analysis principle?
This error is reported if I haven't written. Net for a long time.