DVM DVM - 1 year ago 213
ASP.NET (C#) Question

Unable to translate bytes [FC] at index 35 from specified code page to Unicode

I'm trying to send an object like this to my REST API(built with asp net core)


And this is how the headers form SoapUI look:

Accept-Encoding: gzip,deflate
Content-Type: application/json:charset=UTF-16
Host: localhost:4004
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

However, my
is always invalid because it can not work with the umlaute. The exception is the following:

Unable to translate bytes [FC] at index 35 from specified code page to

If it's any help, the method signature looks like this:

public async Task<IActionResult> Update(string userId, [FromBody] UpdateUserRequest updateRequest)

Basically the code never goes over

if (!actionContext.ModelState.IsValid)
actionContext.Result = new BadRequestObjectResult(actionContext.ModelState);

inside the

What am I missing here?

Jcl Jcl
Answer Source

You are sending your string encoded in utf-16, but telling (in the Content-Type header's charset) it is utf-8.

The bytes for tersü in utf-8 are:


However tersü (in utf-16) contains the bytes (notice the FC there):


(Check it in this fiddle)

So it just can't understand it. So either convert your string to utf-8 in your client before sending it, or set the Content-Type charset to utf-16 .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download