Archived

This forum has been archived. Please start a new discussion on GitHub.

Non-Unicode character MarshalException issue for ice 3.5.1

When I use a c++ client to make a remote call to a C# servant and pass some non unicode character(Chinese character) as message, it cause a MarshalException, the following is the trace mode log:

identity: PdpInterface
facet:
operation: displayMessage
remote host: 192.168.1.115 remote port: 35532
Ice.MarshalException
reason = "Invalid UTF8 string"
在 IceInternal.IncomingBase.handleException__(Exception exc)
Caused by: System.Text.DecoderFallbackException: 无法将位于索引 -1 处的字节 [B7] 由指定的代码页转换为 Unicode。
在 System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
在 System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
在 System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
在 System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder)
在 System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)
在 System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
在 IceInternal.BasicStream.readString()

anyone knows how to solve it? Thanks

Resolved by using MultiByteToWideChar to transfer the non-unicode character to unicode before sending it to C# servant

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Do you convert the string to UTF-8 in your C++ application?

    See C++ Strings and Character Encoding. You either need to manually convert your string to UTF-8 before passing it to Slice operations or install a string converter with the Ice communicator (the Ice runtime will then convert your native strings to UTF-8 before marshaling the string).

    See also the demo/Ice/converter demo from your Ice demo distribution.

    If this doesn't help solving your problem, please provide more information on your platform and application with ideally a small test case that reproduces the problem.

    Cheers,
    Benoit.