Share via

Use UTF8Encoding.GetBytes get some error

济田 胡 1 Reputation point
2020-12-25T08:54:56.233+00:00

My netcore version is 2.0.0
I run it as a server,and I get a error when I write my log: Unable to translate Unicode character \uD83C at index 267 to specified code page.
however it happen just only once,I find the uD83C mean the signal �
first,I check my code,it not change.I also do same action on my test server,it's ok too.
then i search this question online; I find many similar question: https://github.com/dotnet/runtime/issues/594;https://github.com/dotnet/runtime/issues/12183

I want to know how to deal this question,should I use unicode encode?or I should up my version of netcore;
when this error happen,my program will stop,it surely confuse me ,please help me !!!!!

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,661 Reputation points
    2020-12-28T06:10:06.227+00:00

    Hi 21422491,
    You can try to replace characters before you return them or save them using Regex.Replace method.
    More discussion in this link you can refer to.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. Viorel 127K Reputation points
    2020-12-25T09:55:41.877+00:00

    I think that D83C is the first part of a “surrogate pair”. Did you determine which is the code after this character in the string?

    Consider using Unicode or UTF-8 encoding and show some details about the program that has this problem.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.