Open Ccry11 opened 7 months ago
I'm having the same issue, did you manage to find a workaround?
I tried the device factory option also, and that didn't resolve it.
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Using DbContext factory 'DeviceContextFactory'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create a 'DbContext' of type 'DeviceContext'. The exception 'The type initializer for '<Module>' threw an exception.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception.
---> System.TypeInitializationException: The type initializer for 'WinRT.ActivationFactory`1' threw an exception.
---> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
at WinRT.ActivationFactory`1..ctor()
at WinRT.ActivationFactory`1..cctor()
--- End of inner exception stack trace ---
at WinRT.ActivationFactory`1.ActivateInstance[I]()
at Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions..ctor()
at Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManagerCS.AutoInitialize.get_Options() in C:\Users\Wesley\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\include\DeploymentManagerAutoInitializer.cs:line 44
at Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManagerCS.AutoInitialize.AccessWindowsAppSDK() in C:\Users\Wesley\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\include\DeploymentManagerAutoInitializer.cs:line 30
at .cctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.GetActivationInfo(RuntimeType rt, & pfnAllocator, Void*& vAllocatorFirstArg, & pfnCtor, Boolean& ctorIsPublic)
at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContextFromFactory(Type factory, Type contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass20_3.<FindContextTypes>b__9()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Ok, I found a work around. And i'm going to be up front and honest, I found this by luck and have no clue what it is doing or why it works.
I added this to the csproj and then it added the migration.
<WindowsAppSdkDeploymentManagerInitialize>false</WindowsAppSdkDeploymentManagerInitialize>
https://github.com/dotnet/maui/issues/12080#issuecomment-1398635826
@wesleyscaldwell Thank you very much! I confirm that in this way the migration is added and then it can also be applied. I have found a comment about that property: https://github.com/microsoft/microsoft-ui-xaml/issues/8182#issuecomment-1430538408 . I hope that someone can understand why this issue occurs and propose a proper way to fix it
@wesleyscaldwell : Thank you so much! Investigating this issue took me quite some time, your workaround helped! God bless you
I have the same error during debug., and cost few days:
System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'WinRT.ActivationFactory
1' threw an exception. Source=Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection StackTrace: at WinRT.ActivationFactory
1.ActivateInstance[I]() at Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions..ctor() at Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManagerCS.AutoInitialize.get_Options() in C:\Users\Volca.nuget\packages\microsoft.windowsappsdk\1.5.240311000\include\DeploymentManagerAutoInitializer.cs:line 44This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: COMException: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
The error is raised form Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions:
public DeploymentInitializeOptions()
: this(WinRT.ActivationFactory<DeploymentInitializeOptions>.ActivateInstance<IUnknownVftbl>())
{
ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
ComWrappersHelper.Init(_inner, addRefFromTrackerSource: false);
}
Which is called by Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManagerCS.icrosoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManagerCS
I think maybe WinRT.ActivationFactory cann't be initialized. It is said MSIX is running in a container which has some limitation in this artical, such as:
So I unchecked project pproperties of Packaging:
Debug can go again. But I still have questions:
.NET 8 migration on .NET MAUI Blazor Hybrid App causes exception
Unable to create a 'DbContext' of type 'ApplicationDbContext'. The exception 'The type initializer for '<Module>' threw an exception.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
My code
ApplicationDbContext.cs
MauiProgram.cs
Person.cs
PersonConfiguration.cs
MauiApp1.csproj
Stack traces - Vebose output
By runing the command:
dotnet ef migrations add FirstMigration --project MauiApp1 --context ApplicationDbContext --verbose
the following error occurs:Include provider and version information
EF Core version: 8.0.0 Database provider: SqlLite Target framework: .NET 8.0 Operating system: Windows 10 22H2 Build 19045 IDE: Visual Studio 2022 17.8.1 dotnet-ef CLI: 8.0.0