. Net C # bug (temporarily named Bug)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.