0
votes

I'm trying to use DacServices from a Powershell Core script. Unfortunately, it seems DacServices requires System.Diagnostics.Eventing.EventDescriptor, which isn't available in .NET 6. I'm using Powershell Core 7.2.5. Is there a convenient way around this?

I'm loading the types with this code:

$sqlServerDacPaths = "${env:ProgramFiles}\Microsoft SQL Server\150\DAC\bin\Microsoft.SqlServer.Dac.dll", "${env:ProgramFiles}\Microsoft SQL Server\150\DAC\bin\Microsoft.SqlServer.Dac.Extensions.dll"

foreach ($path in $sqlServerDacPaths) {
    if (Test-Path $path) {
        Write-Host "Adding $path"
        Add-Type -Path $path
    }
}

# Instantiate DacServices
$dacServices = New-Object Microsoft.SqlServer.Dac.DacServices $connectionString

The exception I get instantiating DacServices is:

The type initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception... Could not load type 'System.Diagnostics.Eventing.EventDescriptor' from assembly 'System.Core, Version=4.0.0.0

I've tried both the SQL 15 and 16 versions of DacServices without luck.