Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I make migration bundle to behave as if IncludeAllContentForSelfExtract is set? #33112

Open
TomaszWegrzyn opened this issue Feb 16, 2024 · 1 comment

Comments

@TomaszWegrzyn
Copy link

TomaszWegrzyn commented Feb 16, 2024

Description

I am generating migration bundle and getting exception(System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle) when executing the bundle.
It seems to me that the issue is related to one of libraries that I need, specifically SAP Hana EF Core library. It is trying to load Native DLL and failing.
I am under the impression that ef migrations bundle is the same/similar to single file publish, so I would hope I can manipulate IncludeAllContentForSelfExtract setting as well, because I think that should solve the problem I am describing.

When publishing my application as single file, setting <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> in my .csproj indeed prevents System.NotSupportedException, which leads to me believe I would need the same kind of setting for migration bundles.
Unfortunately it seems to not do anything when it comes to migration bundle.

If I am wrong please correct me - maybe I am confused about something.

Details

I am generating bundle with below command

dotnet ef migrations bundle --force --self-contained

Then running the bundle produces following exception:

efbundle.exe --verbose

Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'WebApplication1'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Finding DbContext classes in the project...
Found DbContext 'HanaDbContext'.
Using context 'HanaDbContext'.
Finding design-time services referenced by assembly 'WebApplication1'...
Finding design-time services referenced by assembly 'WebApplication1'...
No referenced design-time services were found.
Finding design-time services for provider 'Sap.EntityFrameworkCore.Hana.v7.0'...
Using design-time services from provider 'Sap.EntityFrameworkCore.Hana.v7.0'.
Finding IDesignTimeServices implementations in assembly 'WebApplication1'...
No design-time services were found.
Creating DbConnection.
'HanaDbContext' disposed.
System.TypeInitializationException: The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception.
 ---> System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
   at System.Reflection.RuntimeAssembly.get_CodeBase()
   at Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls()
   at Sap.Data.Hana.HanaUnmanagedDll..ctor()
   at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
   at Sap.Data.Hana.HanaConnection..cctor()
   --- End of inner exception stack trace ---
   at Sap.Data.Hana.HanaConnection..ctor(String connectionString)
   at Sap.EntityFrameworkCore.Hana.Storage.Internal.HanaRelationalConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.MigrateUsingConnection(IDiagnosticsLogger`1 diagnostics, IMigrator migrator, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsBundle.ExecuteInternal(String[] args)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsBundle.<>c__DisplayClass6_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsBundle.Execute(String context, Assembly assembly, Assembly startupAssembly, String[] args)
The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception.

Note that SAP provides different binaries for Windows and Linux, but same problem happens on Linux(--target-runtime linux-x64) as well as Windows(I am including different dependencies conditionally based on OS)

I can run the application just fine on both OSes when running from Visual Studio or Docker compose. So I don't think OS compatibility has anything to do with it.

Unfortunately I can't show the source code due to closed source, but I hope my explanation is clear enough.

Provider and version information

EF Core version: 7.0.16
Database provider: Sap.EntityFrameworkCore.Hana.v7.0.dll (published via private nuget)
Target framework: (NET 8.0)
Operating systems: Windows 10/Linux

@ajcvickers
Copy link
Member

/cc @maumar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants