microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
389 stars 248 forks source link

Encoding issue related to compilation in container (NAV 2018) #3749

Open RomashkovOleg opened 4 weeks ago

RomashkovOleg commented 4 weeks ago

Hi,

I'm making CI/CD for some legacy NAV 2018 project which uses a lot of local language code/text values and met strange issue related to compilation in container.

Repros

  1. Make a container
    
    $ContainerName = "cronus-2018"
    $artifactUrl = Get-BCArtifactUrl -type OnPrem -version 11
    $password = '123'
    $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
    $credential = New-Object pscredential 'admin', $securePassword

$parameters = @{ "accept_eula" = $true "ContainerName" = $ContainerName "artifactUrl" = $artifactUrl "auth" = "NavUserPassword" "Credential" = $credential "updateHosts" = $true "doNotCheckHealth" = $true "EnableTaskScheduler" = $false "Isolation" = "hyperv" "MemoryLimit" = "8G" } New-NavContainer @parameters -includeCSide -doNotExportObjectsToText


2. Prepare simple test codeunit, which uses local language text. Save it in text format:
[EncodingIssueDemo.txt](https://github.com/user-attachments/files/17628396/EncodingIssueDemo.txt)

OBJECT Codeunit 50000 Encoding Issue Demo { OBJECT-PROPERTIES { Date=; Time=; Version List=Test; } PROPERTIES { Subtype=Test; OnRun=BEGIN END;

} CODE {

[Test]
PROCEDURE LocalLanguageErrorSample@1170000002();
VAR
  GLSetup@1170000000 : Record 98;
BEGIN
  // Some local language comment:
  // пример комментария

  // Sample of local language error
  ERROR('Ошибка');
END;

BEGIN
END.

} }

How it looks in development environment:
<img src=https://github.com/user-attachments/assets/9cf73f04-963a-4a13-9d70-252339d7b8e0 width=400/>

How initial test result looks in test tool interface:
<img src=https://github.com/user-attachments/assets/263cd32b-1f30-435e-9cbb-0d24831db2a0 width=600/>

So far so good.

3. Run script to import and compile this object in container:

Import-ObjectsToNavContainer -containerName cronus-2018 -objectsFile "C:\Temp\EncodingIssueDemo.txt" Compile-ObjectsInNavContainer -containerName cronus-2018 -filter "Type=Codeunit;ID=50000"



4. Run test tool and execute test:
<img src=https://github.com/user-attachments/assets/6bdf91b2-8316-4078-8690-a47ff27d60d1 width=600/>

Same step with debugger:
<img src=https://github.com/user-attachments/assets/b0c272e4-dec5-4928-96bf-bd21a352f046 width=350/>

**Result:** local language text values spoiled.

5. Now go to DevEnv and recompile object manually. After that everything looks as expected (both C/AL code and test result)

In the repository I store objects in UTF8 encoding, so I tried to repeat steps 3-4 with incorrectly encoded file. 
[EncodingIssueDemo_UTF8.txt](https://github.com/user-attachments/files/17628443/EncodingIssueDemo_UTF8.txt)

To my surprise I got expected test result!

But code in DevEnv is spoiled:
<img src=https://github.com/user-attachments/assets/b1271cb0-3b11-4185-b5f8-22ab7884696f width=400/>

And after manual compilation test result is spoiled too:
<img src=https://github.com/user-attachments/assets/a7d6f857-efb9-447b-9488-2ed4f58de9c6 width=400/>

**Additional context**
I tried container with RU system locale, which was made with process isolation. Also I used parameters -locale and - setServiceTierUserLocale for New-NavContainer and -country ru for atifacts. Same result again.

I suppose, that problem is related to compilation in container. I tried to do the same with "finsql.exe command=compileobjects…" but got same result.

I understand that this is obsoleted NAV version and it is not supported any more. But maybe you see the step I missed or you know some trick which could help resolve this?

Thanks!
freddydk commented 4 weeks ago

I won't have time to look at stuff like this for any foreseeable future. if anybody else have seen this before and have a fix or a workaround, please come forward.

Else, you are more than welcome to troubleshoot and create a PR on BcContainerHelper with a fix if you manage to find it.

RomashkovOleg commented 3 weeks ago

I won't have time to look at stuff like this for any foreseeable future. if anybody else have seen this before and have a fix or a workaround, please come forward.

Else, you are more than welcome to troubleshoot and create a PR on BcContainerHelper with a fix if you manage to find it.

Got it. Thanks!