microsoft / DACExtensions

DACExtensions contains samples that extend Data-Tier Applications using DacFx. These samples include deployment contributors and static code analysis rules that can be used with Visual Studio as well as examples of how to use the DacFx public mode
MIT License
125 stars 41 forks source link

Running DacServices.Extract() from a .NET Core 3.1 application results in errors #38

Closed ghost closed 8 months ago

ghost commented 4 years ago

Hello,

I'm trying to generate a DacPac directly from .NET Core application code. My application is configured as a .NET Core 3.1 console application.

Here's an example code I'm running from the console app running on my Linux (CentOS 7.5 base image) host:

using var memoryStream = new MemoryStream();
var connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"

var dacServices = new DacServices(connectionString);

var dacPacExtractOptions = new DacExtractOptions
                                       {
                                               DatabaseLockTimeout = options.DatabaseLockTimeout,
                                               CommandTimeout = options.DatabaseCommandTimeout,
                                               ExtractAllTableData = true,
                                               ExtractApplicationScopedObjectsOnly = false,
                                               ExtractReferencedServerScopedElements = true,
                                               ExtractUsageProperties = false,
                                               IgnoreExtendedProperties = false,
                                               IgnorePermissions = true,
                                               IgnoreUserLoginMappings = true,
                                               LongRunningCommandTimeout = options.DatabaseCommandTimeout,
                                               Storage = DacSchemaModelStorageType.Memory,
                                               VerifyExtraction = true
                                       };

dacServices.Extract(memoryStream, "myDataBase", "myApplication", new Version(1,0,0), extractOptions: dacPacExtractOptions);

I've tried publishing a single file and non-single file, running it with or without sudo. The error I get in all cases is:

Microsoft.Data.Tools.Schema.Extensibility.ExtensibilityException: The extension type Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSchemaModelConstructor could not be instantiated.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.Tools.Schema.SchemaModel.ModelCollation' threw an exception.
 ---> System.ArgumentException: Collation (1033) is not supported on this computer.
   at Microsoft.Data.Tools.Schema.SchemaModel.ModelCollation..ctor(Int32 lcid, Boolean caseSensitive)
   at Microsoft.Data.Tools.Schema.SchemaModel.ModelCollation..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.Tools.Schema.SchemaModel.ModelCollation.get_DefaultCollationCaseInsensitive()
   at Microsoft.Data.Tools.Schema.SchemaModel.DataSchemaModelConstructor..ctor()
   at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSchemaModelConstructor..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at Microsoft.Data.Tools.Schema.Extensibility.ExtensionTypeLoader.InstantiateType[T](Type type)
   --- End of inner exception stack trace --

Surprisingly, you're going to get the same error if you run sqlpackage to generate the dacpac directly, without sudo (I've described the issue/resolution #37 ). However, with calling Dac tools directly from .NET Core results in this error independent of elevation level.