Open svengrav opened 7 months ago
Please supply the log from the generation of the container as well for me to see which version of OS, BC etc.
I have added the full log to the "Full output of scripts" section. Thanks
Version <= "23.2" works as expected.
Tried this on my machine:
$credential = New-Object pscredential -ArgumentList 'admin', (ConvertTo-SecureString -String 'P@ssword1' -Force -AsPlainText)
$artifactUrl = Get-BcArtifactUrl -country de -select Latest
New-BcContainer -Multitenant -UseSSL -Accept_eula -artifactUrl $artifactUrl -Credential $Credential -auth UserPassword
Export-BcContainerDatabasesAsBacpac -sqlCredential $credential -doNotCheckEntitlements -tenant "default"
works fine.
When you say 23.2 works fine - did you test 23.5? (I would assume that the problem would start with 24)
Would it be possible to test this with HyperV isolation? (listed as disabled on your machine)
I have hit some similar problem when I was trying to upgrade some environment to 23.3. In my case, when I imported first the sqlserver module and then the BC admin module, cmdlet "Export-NAVApplication" ended with error:
Export-NAVApplication: Method not found: 'Void Microsoft.Data.SqlClient.SqlConnectionStringBuilder.set_Encrypt(Boolean)'.
I have found that this was problem on my Windows 2019 server and not on Windows 2022 server, which have newer SqlSrv32.dll drivers
When I separated the usage of SqlServer module and BC admin module into separate background jobs, it works ok.
Btw, I was using the "add_AssemblyResolve" trick which is used in the Restore-BcDatabaseFromArtifacts function, but it stopped to work when I moved my management scripts to Pwsh7 and I removed it and separated the SqlServer usage from the BC admin module usage as described in previous post. It means it could be combination of Pwsh7 vs Powershell5 vs Windows 2019 vs Windows 2022 vs SqlSrv32.dll driver version...
Could be connected with https://github.com/microsoft/navcontainerhelper/issues/3527
I have hit some similar problem when I was trying to upgrade some environment to 23.3. In my case, when I imported first the sqlserver module and then the BC admin module, cmdlet "Export-NAVApplication" ended with error:
Export-NAVApplication: Method not found: 'Void Microsoft.Data.SqlClient.SqlConnectionStringBuilder.set_Encrypt(Boolean)'.
I have found that this was problem on my Windows 2019 server and not on Windows 2022 server, which have newer SqlSrv32.dll drivers
When I separated the usage of SqlServer module and BC admin module into separate background jobs, it works ok.
Separating into different sessions is also my colleague's solution.
Would it be possible to test this with HyperV isolation? (listed as disabled on your machine)
Yes i checked that one but it didn't help either. Im wondering if you are using sqlps or the SQLServer module while testing? Maybe that's a problem? In my case the container helper is using the SQLServer Module.
To give you a few more details: I simply use a Bicep Template to deploy the machine. After that i install the Docker host with this script:
$DockerInstall = 'https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/install-docker-ce.ps1'
Invoke-WebRequest $DockerInstall -UseBasicParsing -o installdockerce.ps1
Followed by installing the container helper (latest) and creating a new container (latest). No further modifications are made to the underlying machine and no modifications to the container aswell. I can remove the machine, roll it out again and the problem still exists.
I manged to export the database with 23.2 with the same underlying configuration successfully btw.
The Export to bacpac happens inside the container. I don't load SQLPS or SqlServer directly - I just use Invoke-SqlCmd If running PS5 inside the container (before BC24) - that will (I think) use SQLPS, if running PS7 (BC24 and above) that will use SqlServer, which is installed in the container only in PS7.
If you run other scripts inside the container, which loads SqlServer in PS5 (it isn't installed), then that might be the reason for the failure.
If you try to Remove-BcContainerSession -containerName $containerName before Exporting to bacpac - or set $bccontainerHelperConfig.usePsSession = $false - that would be worth trying out.
I cannot repro the problem
I seem to have the same problem. Trying to get a local Business Central instance running in Docker for development purposes.
$containerName = 'bcsandbox'
$tenantId = 'default'
$tenantBacpac = "C:\ProgramData\BcContainerHelper\Production_20240522_01.bacpac"
$artifactUrl = Get-BcArtifactUrl `
-type sandbox `
-country "fr" `
-version "24.0.16410.17628" `
-select Closest
Write-Output $artifactUrl
New-BCContainer `
-accept_eula `
-containerName $containerName `
-multitenant `
-artifactUrl $artifactUrl
I can access the BC tenant in my browser but only with the default Cronus database.
Now trying to insert a database export from our BC Online production tenant.
Restore-DatabasesInBcContainer `
-bakFile $tenantBacpac `
-containerName $containerName `
-databaseName 'default'
Results in the same logs an identical error:
Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Also using PowerShell 7.
Quite new to this, not sure if there is something I can do to fix this?
(I have no export of a v23 database so cannot try if it works on this version. Inserting the v24 bacpac into a v23 BC Docker results in "incorrectly formed" error by SQL Server.)
PowerShell v5 produces to same error
PS C:\WINDOWS\system32> Restore-DatabasesInBcContainer -bakFile "C:\ProgramData\BcContainerHelper\Production_20240522_01.bacpac" -containerName 'bcsandbox' -databaseName 'default'
BcContainerHelper version 6.0.17
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.22621.2506
Restoring C:\ProgramData\BcContainerHelper\Production_20240522_01.bacpac to default
Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Exception Script Stack Trace:
at Restore, <No file>: line 25
at <ScriptBlock>, <No file>: line 40
PowerShell Call Stack:
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 71
at Restore-DatabasesInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\Bacpac\Restore-DatabasesInNavContainer.ps1: line 73
at <ScriptBlock>, <No file>: line 1
Container Free Physical Memory: 11.2Gb
Services in container bcsandbox:
Restore-DatabasesInBcContainer Telemetry Correlation Id: f987cab3-62da-4c0b-9736-ffacf01e93c2
Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Invoke-ScriptInNavContainer.ps1:112 char:13
+ throw $errorMessage
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Could not load ...9793829ddae60'.:String) [], RuntimeException
+ FullyQualifiedErrorId : Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb97
93829ddae60'.
More specifically, the error raises in Invoke-ScriptInNavContainer
(fucntion Invoke-ScriptInBcContainer
) on line 287 when executing a .ps1 script in the container.
docker exec bcsandbox pwsh "C:\ProgramData\BcContainerHelper\f4159623-3429-4daa-87c3-693432c7ab83.ps1"
Any solution for this yet? Just tried to restore the database for my new container and got the same error message as above :(
@awpehl - and if you run with PS5 it works ?
PowerShell v5 produces to same error
PS C:\WINDOWS\system32> Restore-DatabasesInBcContainer -bakFile "C:\ProgramData\BcContainerHelper\Production_20240522_01.bacpac" -containerName 'bcsandbox' -databaseName 'default' BcContainerHelper version 6.0.17 BC.HelperFunctions emits usage statistics telemetry to Microsoft Running on Windows, PowerShell 5.1.22621.2506 Restoring C:\ProgramData\BcContainerHelper\Production_20240522_01.bacpac to default Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Exception Script Stack Trace: at Restore, <No file>: line 25 at <ScriptBlock>, <No file>: line 40 PowerShell Call Stack: at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 71 at Restore-DatabasesInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\Bacpac\Restore-DatabasesInNavContainer.ps1: line 73 at <ScriptBlock>, <No file>: line 1 Container Free Physical Memory: 11.2Gb Services in container bcsandbox: Restore-DatabasesInBcContainer Telemetry Correlation Id: f987cab3-62da-4c0b-9736-ffacf01e93c2 Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Invoke-ScriptInNavContainer.ps1:112 char:13 + throw $errorMessage + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (Could not load ...9793829ddae60'.:String) [], RuntimeException + FullyQualifiedErrorId : Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb97 93829ddae60'.
You need to be running PS5 inside the container
@awpehl - and if you run with PS5 it works ?
I already tried PS5 for the general script but didn't work. How can I run the PS5 inside the container?
run $bcContainerHelperConfig.usePwshForBc24 = $false
after importing bccontainerhelper and before running your script
run
$bcContainerHelperConfig.usePwshForBc24 = $false
after importing bccontainerhelper and before running your script
Worked for me! Thanks 👍
Just note that now everything else inside the container runs PowerShell 5 as well - and as a result of this, runs slower.
And how is this supposed to work if the PS bridge is removed with v26? And what about the other known issues (like missing files and other stuff) that are worked around today by forcing the good old Windows PS?
Btw.: The dll has several versions in only one container:
I have asked them to NOT remove the bridge in v26. My suggestion is to go away from the entire PS5 / PS7 thingy - and create a BC CLI instead - and then create a PS module, which calls the CLI and works on whatever PS version + python and other scripting languages. So, I think the bridge will stay until we are there.
That is a good idea in the current situation. Thank you for providing this information.
Describe the issue There is a compatibility problem between NAVTools DLLs and SQL Server Tools DLLs. This means that required dependencies cannot be resolved and this leads to an assembly error. Here the modules probably have to be loaded in separate sessions with New-PSSession & Invoke-Command { SQL Cmds ... }
Scripts used to create container and cause the issue
Full output of scripts
Screenshots
Additional context This seems to be a general problem when loading the DLLS between NAVTools and SQLServer Tools.