microsoft/DacFx

Missing references in SQLpackage contributor extension (DeploymentPlanModifier)

BarrydeBoerUMCG opened this issue · 3 comments

  • SqlPackage or DacFx Version: 16.0.6296
  • .NET Framework (Windows-only) or .NET Core: 4.8.
  • Environment (local platform and source/target platforms): windows server 2022

We created a sqlpackage contributor extension (DeploymentPlanModifier) to filter objects during the deployment of a dacpac.
On our development environment (with VS2022 installed) this works fine.

Steps to Reproduce:

  1. We copied the signed dll and pdb from our VS2022 project to the extensions folder of sqlpackage (C:\Program Files\Microsoft SQL Server\160\DAC\bin\Extensions) to the remote machine
  2. Verified that these files are unblocked
  3. Added 'AdditionalDeploymentContributors' argument to sqlpackage.exe to include the extension
  4. Run the deployment in a Devops Release pipeline, calling sqlpackage on the remote machine

We get a ReflectionTypeLoadException, probably indicating a missing reference!?

SafeDirectoryCatalog: Extensibility failed to load DLL 'C:\Program Files\Microsoft SQL Server\160\DAC\bin\Extensions\ContributorSubfolder\OurContributor.dll' due to an exception System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) 
   at System.Reflection.Assembly.GetTypes() 
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog() 
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetEnumerator() 
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source) 
   at Microsoft.SqlServer.Dac.Extensibility.DacExtensionHelper.TryLoadAssemblyCatalog(String file, ComposablePartCatalog& catalog)

Can anyone give an indication on how to solve this issue??

Did this occur in prior versions? If not - which version(s) did it work in?

(DacFx/SqlPackage/SSMS/Azure Data Studio)

Interesting. Is the version of SqlPackage in your development environment (from Visual Studio 2022) the same as SqlPackage in your deployment environment? Ideally, they're both 162.x but validating that they're the same helps narrow down the reproducibility.
@zijchen for assembly loading expertise

On the environment it does work, sqlpackage version 16.1.6374.0 is installed.
Where it doesn't work, version 16.0.6296
Comparing the 2 enviroments it looks al the same to us; .Net 4.8 installed (created the contributor in this version), sqlpackage and the dll installed in the exact same place (C:\Program Files\Microsoft SQL Server\160\DAC\bin\Extensions\SubFolder\OurContributor.dll), except for the version of sqlpackage...

oh, well that's good news! it not working with Sqlpackage from 2022 (16.0.6296 - https://learn.microsoft.com/en-us/sql/tools/sqlpackage/release-notes-sqlpackage?view=sql-server-ver16#192-sqlpackage) means that you likely will be sorted out by updating your deployment environment.

now might be a good time to move over to the sqlpackage dotnet tool, but if not there's still a bunch of ways to install - https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-download?view=sql-server-ver16

(current sqlpackage version is 162.3.x)