microsoft / navcontainerhelper

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

Error running Run-TestsInBCContainer for BC21.0 #2820

Closed spookymattress closed 1 year ago

spookymattress commented 1 year ago

Describe the issue Getting an error when running tests using the powershell script "Run-TestsInBCContainer" on Docker BC21.0 DK.

Tests runs fine in the browser using AL Test Tool

Scripts used to create container and cause the issue

        $additionalParameters = @("--volume ""${ArtifactDirectory}:C:\Source""")  

        New-BCContainer @parameters `
                         -containerName $containerName `
                         -artifactUrl $artifactUrl `
                         -auth NavUserPassword `
                         -Credential $credentials `
                         -shortcuts "None" `
                         -updateHosts `
                         -licenseFile "$licenseFile" `
                         -additionalParameters $additionalParameters `
                         -includeTestToolkit `
                         -enableTaskScheduler:$false

Full output of scripts

PS C:\Windows\system32> Run-TestsInBCContainer -containerName 'CLOUD' -XUnitResultFileName 'E:\containerhelper\Extensions\CLOUD\test.xml' -testSuite 'DEFAULT' -credential $credential -companyName 'My Company'
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : >>> public class MyOpenFormInteraction : Microsoft.Dynamics.Framework.UI.Client.Interactions.OpenFormInteraction

c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(2) : {

Exception Script Stack Trace:
at <ScriptBlock>, C:\programdata\bccontainerhelper\Extensions\CLOUD\PsTestTool\ClientContext.ps1: line 22
at <ScriptBlock>, C:\programdata\bccontainerhelper\Extensions\CLOUD\PsTestTool\PsTestFunctions.ps1: line 17
at <ScriptBlock>, <No file>: line 46

PowerShell Call Stack:
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\4.0.7\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 71
at Run-TestsInBcContainer, C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\4.0.7\AppHandling\Run-TestsInNavContainer.ps1: line 373
at <ScriptBlock>, <No file>: line 1

Container Free Physical Memory: 6.8Gb

Services in container CLOUD:
- MicrosoftDynamicsNavServer$BC is Running
- MSSQL$SQLEXPRESS is Running

Run-TestsInBCContainer Telemetry Correlation Id: 612984c0-5adc-4d68-86c4-e47c114648fb
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : >>> public class MyOpenFormInteraction : Microsoft.Dynamics.Framework.UI.Client.Interactions.OpenFormInteraction
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(2) : {
At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\4.0.7\AppHandling\Run-TestsInNavContainer.ps1:508 char:17
+                 throw $_.Exception.Message
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (c:\Users\Contai...2.0.cs(2) : {
:String) [], RuntimeException
    + FullyQualifiedErrorId : c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference
    to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(1) : >>> public class MyOpenFormInteraction : Microsoft.Dynamics.Framework.UI.Client.Interactions.OpenFormInteraction
c:\Users\ContainerAdministrator\AppData\Local\Temp\rpxjq3j2\rpxjq3j2.0.cs(2) : {

...

Screenshots

Screenshot where Run-TestsInBCContainer is run directly from PS.

image

Additional context Fails every time, started failing in DevOps Pipelines, also fails when running script from powershell. Using new bc21 licensefile in the new .bclicense format. Looks to be the same issue as #2740

freddydk commented 1 year ago

Did you try on 21.1? I do remember that some version was shipped with a wrong dotnet DLL in the client assemblies.

spookymattress commented 1 year ago

Yes, did that and that failed as well.

But, the problem arises if you have an old version of BCContainerHelper installed and are reusing the container, and only restoring/backup the database on each build. As our container initially was created with an old version of BCContainerHelper, the two PS files (ClientContext.ps1, PsTestFunctions.ps1) in PsTestTool dir were copied in from an old version, and that did not work when running the tests. So, even if we are using the newest version of BCCH, the two PS files in PsTestTool is never overwritten when re-using the container.

fvet commented 1 year ago

As a reference

I faced the same issue today and performed following steps to resolve:

image

freddydk commented 1 year ago

Got it, the problem is really that I cannot replace the files (DLLs) as these are locked. Updating containerhelper and recreating the container should fix the issue.

Thanks