azure-functions-templates icon indicating copy to clipboard operation
azure-functions-templates copied to clipboard

C# Item Template is garbled in multi-byte characters (CJK)

Open shibayan opened this issue 5 years ago • 7 comments

Using multibyte characters causes garbled characters. Visual Studio saves file in Windows default encoding if the file does not have UTF-8 BOM.

shibayan avatar Dec 11 '18 07:12 shibayan

If I use string interpolation of ILogger in function app class, log is garbled when using multi-bytes character.

e.g.

log.LogInformation("ほげほげ: {0}", data);  //no problem
log.LogInformation($"ふがふが: {data}"); //garbled

image

I should ALWAYS change to UTF-8 (with BOM) from default function app code (*.cs) after create project or add function.

buchizo avatar Dec 16 '19 07:12 buchizo

@soninaren Is this issue recognized? If I can contribute, I will do it happily 😃

shibayan avatar Dec 19 '19 12:12 shibayan

@shibayan Are you looking at the logs in Application Insights? If yes this is a know issue. https://github.com/Azure/azure-functions-host/issues/4731

soninaren avatar Dec 19 '19 19:12 soninaren

@soninaren Thank you for the reply.

Yes, the above image is certainly from Application Insights, but the problem is different.

This problem, Visual Studio saves using the system default encoding (Shift_JIS in Japan) because the Azure Functions project template does not have a UTF-8 BOM.

There is no problem when building on the machine used for development, but there is a problem when combined with CI services such as Azure DevOps.

Repro steps

  1. Create new azure function project with HttpTrigger
  2. Modity OkObjectResult and save
// Replace Hello => こんにちは
(ActionResult)new OkObjectResult($"こんにちは, {name}")
  1. Push to Azure Repos (garbled)

image

  1. Build and Deploy (garbled)

Build with windows agent

image

Build with ubuntu agent

image

Solution

Converting the .cs file to utf-8 + bom encoding will fix it.

image

shibayan avatar Dec 20 '19 07:12 shibayan

@soninaren

Hey! How is your progress?

In the meantime, we developers who use multi-byte languages are still manually re-saving in UTF-8.

shibayan avatar Aug 29 '20 18:08 shibayan

@shibayan, this a host issue, check this issue https://github.com/Azure/azure-functions-host/issues/4731 for updates. I don't think there is active work for the host work item. It has been added to the triage milestone. Going to close this one out since this is not a templates issue.

soninaren avatar Sep 01 '20 23:09 soninaren

@soninaren This is not the AppInsights issue. The root cause is the following shibayan wrote.

This problem, Visual Studio saves using the system default encoding (Shift_JIS in Japan) because the Azure Functions project template does not have a UTF-8 BOM.

Please change Azure Functions template file encoding to UTF-8 BOM from UTF-8 to fix this issue for non ascii users.

Thank you.

runceel avatar Sep 25 '20 15:09 runceel