microsoft / navcontainerhelper

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

Assembly Dependency Error between SQL Server Module and NAV Tools in BC Container #3529

Open svengrav opened 2 months ago

svengrav commented 2 months ago

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

 $ContainerImage = Get-BCArtifactUrl -Select Latest -Type Sandbox -Country de
 $Credential = [PSCredential]::new("azadmin", (ConvertTo-SecureString $Password -AsPlainText -Force ))
  New-BcContainer -UseTraefik -Multitenant -UpdateHosts -UseSSL -Accept_eula -artifactUrl $ContainerImage -Credential $Credential -auth UserPassword -PublicDnsName $PublicDNSName

Export-BcContainerDatabasesAsBacpac -sqlCredential ([PSCredential]::new("azadmin", (ConvertTo-SecureString $Password -AsPlainText -Force))) -doNotCheckEntitlements -tenant "default"

Full output of scripts

BcContainerHelper is version 6.0.17
BcContainerHelper is running as administrator
HyperV is Disabled
Host is Microsoft Windows Server 2022 Datacenter Azure Edition - 10.0.20348.2402
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 26.1.1
Docker Server Version is 26.1.1
Removing Session bcserver
Removing container bcserver
Removing entries from hosts
Removing bcserver from container hosts file
Removing bcserver-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\bcserver
Downloading artifact /sandbox/24.0.16410.19115/de
Downloading C:\Users\azadmin\AppData\Local\Temp\9d4262f4-9f85-4d2e-813d-f33311c24691.zip
Unpacking artifact to tmp folder using Expand-Archive
Downloading platform artifact /sandbox/24.0.16410.19115/platform
Downloading C:\Users\azadmin\AppData\Local\Temp\506b2ac9-f64e-4441-a2ea-bef055357a04.zip
Unpacking artifact to tmp folder using Expand-Archive
Downloading Prerequisite Components
Downloading c:\bcartifacts.cache\sandbox\24.0.16410.19115\platform\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw_x64.msi
Downloading c:\bcartifacts.cache\sandbox\24.0.16410.19115\platform\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-WindowsHosting.exe
Fetching all docker images
Fetching all docker volumes
Enabling SSL as otherwise all clients will see mixed HTTP / HTTPS request, which will cause problems e.g. on the mobile and modern windows clients
Using image mcr.microsoft.com/businesscentral:ltsc2022
PublicDnsName is veo-testbox.gws-cloud.de
Creating Container bcserver
Style: sandbox
Multitenant: Yes
Version: 24.0.16410.19115
Platform: 24.0.19098.0
Generic Tag: 1.0.2.20
Container OS Version: 10.0.20348.2402 (ltsc2022)
Host OS Version: 10.0.20348.2402 (ltsc2022)
Using process isolation
Using locale de-DE
Adding special CheckHealth.ps1 to enable Traefik support
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Additional Parameters:
--expose 5986
-e webserverinstance=bcserver
-e publicdnsname=veo-testbox.gws-cloud.de
-l "traefik.protocol=https"
-l "traefik.web.frontend.rule=PathPrefix:/bcserver"
-l "traefik.web.port=443"
-l "traefik.soap.frontend.rule=PathPrefix:/bcserversoap;ReplacePathRegex: ^/bcserversoap(.*) /BC$1"
-l "traefik.soap.port=7047"
-l "traefik.rest.frontend.rule=PathPrefix:/bcserverrest;ReplacePathRegex: ^/bcserverrest(.*) /BC$1"
-l "traefik.rest.port=7048"
-l "traefik.dev.frontend.rule=PathPrefix:/bcserverdev;ReplacePathRegex: ^/bcserverdev(.*) /BC$1"
-l "traefik.dev.port=7049"
-l "traefik.snap.frontend.rule=PathPrefix:/bcserversnap;ReplacePathRegex: ^/bcserversnap(.*) /BC$1"
-l "traefik.snap.port=7083"
-l "traefik.dl.frontend.rule=PathPrefixStrip:/bcserverdl"
-l "traefik.dl.port=8080"
-l "traefik.dl.protocol=http"
-l "traefik.enable=true"
-l "traefik.frontend.entryPoints=https"
--env customNavSettings=PublicODataBaseUrl=https://veo-testbox.gws-cloud.de/bcserverrest/odata,PublicSOAPBaseUrl=https://veo-testbox.gws-cloud.de/bcserversoap/ws,PublicWebBaseUrl=https://veo-testbox.gws-cloud.de/bcserver
Files in C:\ProgramData\BcContainerHelper\Extensions\bcserver\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- CheckHealth.ps1
- HelperFunctions.ps1
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container bcserver from image mcr.microsoft.com/businesscentral:ltsc2022
fa0f7cb3fc32c398a520557b3c69bf26e2b565a1b1c9e743c0c9547356c01abc
Waiting for container bcserver to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.0.16410.19115/de
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.0.16410.19115\de, platformArtifactPath=c:\dl\sandbox\24.0.16410.19115\platform, databasePath=c:\dl\sandbox\24.0.16410.19115\de\BusinessCentral-DE.bak, licenseFilePath=c:\dl\sandbox\24.0.16410.19115\de\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.0.16410.19115\platform\ServiceTier\Program Files
c:\dl\sandbox\24.0.16410.19115\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.0.16410.19115\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
Copying ConfigurationPackages
C:\dl\sandbox\24.0.16410.19115\de\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.0.16410.19115\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.0.16410.19115\de\Extensions
Copying Applications
C:\dl\sandbox\24.0.16410.19115\platform\Applications
Copying Applications.DE
C:\dl\sandbox\24.0.16410.19115\de\Applications.DE
Copying dependencies
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing license file
Copying Database on localhost\SQLEXPRESS from tenant to default
Taking database tenant offline
Copying database files
Attaching files as new Database default
Putting database tenant back online
Mounting tenant database
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Stopping Business Central Service Tier
Installation took 314 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.28.208.1 in container hosts file
Starting Container
Hostname is bcserver
PublicDnsName is veo-testbox.gws-cloud.de
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 32E7EFD88CE7CF97CF8191BC2B15DDCD63F4F1D1
DNS identity veo-testbox.gws-cloud.de
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting PublicODataBaseUrl to https://veo-testbox.gws-cloud.de/bcserverrest/odata
Setting PublicSOAPBaseUrl to https://veo-testbox.gws-cloud.de/bcserversoap/ws
Setting PublicWebBaseUrl to https://veo-testbox.gws-cloud.de/bcserver
Starting Service Tier
CertificateThumprint 32E7EFD88CE7CF97CF8191BC2B15DDCD63F4F1D1
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: bcserver
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\bcserver
Create the application pool bcserver
Create website: NavWebApplicationContainer with SSL
Update configuration: navsettings.json
Done Configuring Web Client
Enabling Financials User Experience
Dismounting Tenant
Mounting Tenant
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Creating http download site
Setting SA Password and enabling SA
Creating azadmin as SQL User and add to sysadmin
Creating SUPER user
Enable PSRemoting and setup user for winrm
Creating self-signed certificate for winrm
Container IP Address: 172.28.216.189
Container Hostname  : bcserver
Container Dns Name  : veo-testbox.gws-cloud.de
Web Client          : https://veo-testbox.gws-cloud.de/bcserver/?tenant=default
Dev. Server         : https://veo-testbox.gws-cloud.de
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting bcserver to 172.28.216.189 in host hosts file
Setting bcserver-default to 172.28.216.189 in host hosts file
Setting bcserver-default to 172.28.216.189 in container hosts file

Files:
http://veo-testbox.gws-cloud.de:8080/ALLanguage.vsix
http://veo-testbox.gws-cloud.de:8080/certificate.cer

Container Total Physical Memory is 8.0Gb
Container Free Physical Memory is 1.4Gb

Initialization took 81 seconds
Ready for connections!
Reading CustomSettings.config from bcserver
Creating Desktop Shortcuts for bcserver
Cleanup old dotnet core assemblies
Container bcserver successfully created
Because of Traefik, the following URLs need to be used when accessing the container from outside your Docker host:
Web Client:        https://veo-testbox.gws-cloud.de/bcserver?tenant=default
SOAP WebServices:  https://veo-testbox.gws-cloud.de/bcserversoap
OData WebServices: https://veo-testbox.gws-cloud.de/bcserverrest
Dev Service:       https://veo-testbox.gws-cloud.de/bcserverdev
Snapshot Service:  https://veo-testbox.gws-cloud.de/bcserversnap
File downloads:    https://veo-testbox.gws-cloud.de/bcserverdl
Health check returns False, restarting container
Removing Session bcserver
bcserver
Waiting for container bcserver to be ready

Initializing...
Setting host.containerhelper.internal to 172.28.208.1 in container hosts file
Restarting Container
PublicDnsName unchanged
Hostname is bcserver
PublicDnsName is veo-testbox.gws-cloud.de
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Starting Service Tier
Container IP Address: 172.28.210.1
Container Hostname  : bcserver
Container Dns Name  : veo-testbox.gws-cloud.de
Web Client          : https://veo-testbox.gws-cloud.de/bcserver?tenant=default
Dev. Server         : https://veo-testbox.gws-cloud.de
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting bcserver to 172.28.210.1 in host hosts file
Setting bcserver-default to 172.28.210.1 in host hosts file
Setting bcserver-default to 172.28.210.1 in container hosts file

Files:
http://veo-testbox.gws-cloud.de:8080/ALLanguage.vsix
http://veo-testbox.gws-cloud.de:8080/certificate.cer

Container Total Physical Memory is 8.0Gb
Container Free Physical Memory is 3.5Gb

Initialization took 11 seconds
Ready for connections!
Waiting for tenants to be mounted

Use:
Get-BcContainerEventLog -containerName bcserver to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName bcserver to get debug information about the container
Enter-BcContainer -containerName bcserver to open a PowerShell prompt inside the container
Remove-BcContainer -containerName bcserver to remove the container again
docker logs bcserver to retrieve information about URL's again

-------------------------------------------------
Export-BcContainerDatabasesAsBacpac -sqlCredential ([PSCredential]::new("azadmin", (ConvertTo-SecureString "%7~0&45[vVzG" -AsPlainText -Force))) -doNotCheckEntitlements -tenant "default"

Copying Database on localhost\SQLEXPRESS from CRONUS to tempCRONUS
Removing Database tempCRONUS from localhost\SQLEXPRESS
Taking database CRONUS offline
Copying database files
Attaching files as new Database tempCRONUS
Putting database CRONUS back online
Remove Windows Users from tempCRONUS
Remove Application Roles from tempCRONUS
Remove data from System Tables database tempCRONUS
Remove Network Service User from tempCRONUS
Remove System User from tempCRONUS
Exporting as BacPac...
Connecting to database 'tempCRONUS' on server 'localhost\SQLEXPRESS'.
Extracting schema
Extracting schema from database
Resolving references in schema model
Validating schema model
Validating schema model for data package
Validating schema
Exporting data from database
Exporting data
Processing Export.
Processing Table '[dbo].[Configuration Package File]'.
Processing Table '[dbo].[Entitlement Set]'.
Processing Table '[dbo].[Entitlement]'.
Processing Table '[dbo].[Membership Entitlement]'.
Processing Table '[dbo].[Page Documentation]'.
Processing Table '[dbo].[OData Edm Type]'.
Processing Table '[dbo].[Upgrade Blob Storage]'.
Processing Table '[dbo].[Report Layout]'.
Processing Table '[dbo].[Media Resources]'.
Processing Table '[dbo].[NAV App Resource]'.
Processing Table '[dbo].[NAV App Publish Reference]'.
Processing Table '[dbo].[Power BI Blob]'.
Processing Table '[dbo].[Power BI Default Selection]'.
Processing Table '[dbo].[$ndo$dbproperty]'.
Processing Table '[dbo].[$ndo$tenants]'.
Processing Table '[dbo].[$ndo$cachesync]'.
Processing Table '[dbo].[$ndo$taskscheduling]'.
Processing Table '[dbo].[$ndo$inplacepublishingstate]'.
Processing Table '[dbo].[$ndo$inplacepublishingstatus]'.
Processing Table '[dbo].[$ndo$inplacepublishingworkloads]'.
Processing Table '[dbo].[$ndo$inplacepublishingbaseline]'.
Processing Table '[dbo].[$ndo$textlookup]'.
Processing Table '[dbo].[$ndo$textmap]'.
Processing Table '[dbo].[$ndo$textobjectmap]'.
Processing Table '[dbo].[Object]'.
Processing Table '[dbo].[Object Metadata]'.
Processing Table '[dbo].[Server Instance]'.
Processing Table '[dbo].[Add-in]'.
Processing Table '[dbo].[NAV App Object Metadata]'.
Processing Table '[dbo].[NAV App Tenant App]'.
Processing Table '[dbo].[NAV App]'.
Processing Table '[dbo].[NAV App Dependencies]'.
Processing Table '[dbo].[NAV App Capabilities]'.
Processing Table '[dbo].[NAV App Object Prerequisites]'.
Processing Table '[dbo].[Media]'.
Processing Table '[dbo].[Media Set]'.
Processing Table '[dbo].[Published Application]'.
Processing Table '[dbo].[Application Object Metadata]'.
Processing Table '[dbo].[Application Dependency]'.
Processing Table '[dbo].[Installed Application]'.
Processing Table '[dbo].[Inplace Installed Application]'.
Processing Table '[dbo].[Report Layout Definition]'.
Processing Table '[dbo].[Application Resource]'.
Processing Table '[dbo].[Permission Set]'.
Processing Table '[dbo].[Permission]'.
Processing Table '[dbo].[Debugger Breakpoint]'.
Processing Table '[dbo].[Debugger Watch]'.
Processing Table '[dbo].[Send-To Program]'.
Processing Table '[dbo].[Style Sheet]'.
Processing Table '[dbo].[Profile]'.
Processing Table '[dbo].[Profile Metadata]'.
Processing Table '[dbo].[Profile Page Metadata]'.
Processing Table '[dbo].[Chart]'.
Processing Table '[dbo].[Web Service]'.
Successfully exported database and saved it to file 'C:\ProgramData\BcContainerHelper\Extensions\bcserver\app.bacpac'.
Time elapsed 0:00:26.17
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 <ScriptBlock>, <No file>: line 426
at <ScriptBlock>, <No file>: line 423

PowerShell Call Stack:
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Invoke-ScriptInNavContainer.ps1: l
ine 71
at Export-BcContainerDatabasesAsBacpac, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\Bacpac\Export-NavContainerDatabasesAsBacpac
.ps1: line 70
at <ScriptBlock>, <No file>: line 1

Container Free Physical Memory: 1.8Gb

Services in container bcserver:
Export-BcContainerDatabasesAsBacpac Telemetry Correlation Id: 9e45f492-c52a-4525-80a7-501b3d7e5083
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.De 
   pendencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
...

Screenshots

Additional context This seems to be a general problem when loading the DLLS between NAVTools and SQLServer Tools.

freddydk commented 2 months ago

Please supply the log from the generation of the container as well for me to see which version of OS, BC etc.

svengrav commented 2 months ago

I have added the full log to the "Full output of scripts" section. Thanks

svengrav commented 2 months ago

Version <= "23.2" works as expected.

freddydk commented 2 months ago

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)

freddydk commented 2 months ago

Would it be possible to test this with HyperV isolation? (listed as disabled on your machine)

kine commented 2 months ago

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.

kine commented 2 months ago

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...

kine commented 2 months ago

Could be connected with https://github.com/microsoft/navcontainerhelper/issues/3527

svengrav commented 2 months ago

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.

svengrav commented 2 months ago

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.

freddydk commented 2 months ago

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

WCONFR commented 1 month ago

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.)

WCONFR commented 1 month ago

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'.
WCONFR commented 1 month ago

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"

f4159623-3429-4daa-87c3-693432c7ab83.txt

awpehl commented 3 weeks ago

Any solution for this yet? Just tried to restore the database for my new container and got the same error message as above :(

freddydk commented 3 weeks ago

@awpehl - and if you run with PS5 it works ?

freddydk commented 3 weeks ago

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 commented 3 weeks ago

@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?

freddydk commented 3 weeks ago

run $bcContainerHelperConfig.usePwshForBc24 = $false after importing bccontainerhelper and before running your script

awpehl commented 3 weeks ago

run $bcContainerHelperConfig.usePwshForBc24 = $false after importing bccontainerhelper and before running your script

Worked for me! Thanks 👍

freddydk commented 3 weeks ago

Just note that now everything else inside the container runs PowerShell 5 as well - and as a result of this, runs slower.