Umbraco-CMS: Error on startup after 12.1 upgrade
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
12.1
Bug summary
We had a v11 site which we upgraded successfully to v12. We’ve just tried to upgrade the site to v12.1 and are encountering the following error when trying to start the site:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Umbraco.Cms.Persistence.EFCore.Migrations.IMigrationProvider Lifetime: Singleton ImplementationType: Umbraco.Cms.Persistence.EFCore.SqlServer.SqlServerMigrationProvider': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.IDbContextFactory1[Umbraco.Cms.Persistence.EFCore.UmbracoDbContext]’ while attempting to activate ‘Umbraco.Cms.Persistence.EFCore.SqlServer.SqlServerMigrationProvider’.) (Error while validating the service descriptor ‘ServiceType: Umbraco.Cms.Persistence.EFCore.Migrations.IMigrationProvider Lifetime: Singleton ImplementationType: Umbraco.Cms.Persistence.EFCore.Sqlite.SqliteMigrationProvider’: Unable to resolve service for type ‘Microsoft.EntityFrameworkCore.IDbContextFactory1[Umbraco.Cms.Persistence.EFCore.UmbracoDbContext]' while attempting to activate 'Umbraco.Cms.Persistence.EFCore.Sqlite.SqliteMigrationProvider'.) (Error while validating the service descriptor 'ServiceType: Umbraco.Cms.Infrastructure.Migrations.IEFCoreMigrationExecutor Lifetime: Singleton ImplementationType: Umbraco.Cms.Persistence.EFCore.EfCoreMigrationExecutor': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.IDbContextFactory1[Umbraco.Cms.Persistence.EFCore.UmbracoDbContext]’ while attempting to activate ‘Umbraco.Cms.Persistence.EFCore.SqlServer.SqlServerMigrationProvider’.) (Error while validating the service descriptor ‘ServiceType: Umbraco.Cms.Core.Events.INotificationAsyncHandler1[Umbraco.Cms.Infrastructure.Migrations.Notifications.DatabaseSchemaAndDataCreatedNotification] Lifetime: Transient ImplementationType: Umbraco.Cms.Persistence.EFCore.Composition.EFCoreCreateTablesNotificationHandler': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.IDbContextFactory1[Umbraco.Cms.Persistence.EFCore.UmbracoDbContext]’ while attempting to activate ‘Umbraco.Cms.Persistence.EFCore.SqlServer.SqlServerMigrationProvider’.) (Error while validating the service descriptor ‘ServiceType: Umbraco.Cms.Core.Events.INotificationAsyncHandler1[Umbraco.Cms.Core.Notifications.UnattendedInstallNotification] Lifetime: Transient ImplementationType: Umbraco.Cms.Persistence.EFCore.Composition.EFCoreCreateTablesNotificationHandler': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.IDbContextFactory1[Umbraco.Cms.Persistence.EFCore.UmbracoDbContext]’ while attempting to activate ‘Umbraco.Cms.Persistence.EFCore.SqlServer.SqlServerMigrationProvider’.)'`
I don’t know if anybody has any ideas?
Specifics
No response
Steps to reproduce
Upgrade a v11 site to v12, upgrade to v12.1 in Visual Studio then attempt to run the site.
Expected result / actual result
The site should run and the upgrade process should run.
This item has been added to our backlog AB#31902
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 15 (13 by maintainers)
Hi everyone. That’s really interesting 🤔
I can reproduce this on a fresh 12.1 install by removing
.AddDeliveryApi()fromConfigureServicesinStartup. That’s … unexpected to say the least.We’ll look into this 🔍
Hello @richarth and @arknu I solved the issue for my project going from 12.0.1 to 12.1.0.
Can you guys inside your project find the Startup.cs file and inside that file try to search for the pisce of code
.AddDeliveryApi()If you missing this line inside the Startup.cs file then search for.AddWebsite()and the add the.AddDeliveryApi()as in the next of the pipe chain so you end up with this in the methodConfigureServicesand the try to rerun the website. It fix my error.
If you have the .AddDeliveryApi() inside your startup file, please also return then i can debug futher
Heya, this has been fixed in #14678 which is @nikcio’s PR but without the breaking change 😄 So big thank you for that 😄
This change has already been released in 12.1.1, which is available on Nuget, so I’ll go ahead and close this issue, thanks again.
@kjac found some inside the Umbraco.Cms.Api.Delivery.DependencyInjection.UmbracoBuilderExtensions add in the
UmbracoDbContextContext.So deleting the line
AddDeliveryApi()will acully do the the EF Core context of type UmbracoDbContext never exiting in the DI. So when Umbraco is starting is hit the composer https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Cms.Persistence.EFCore/Composition/UmbracoEFCoreComposer.csthat dependens on the
UmbracoDbContextbut again never added to the ServiceProvider scope.Hi,
Thanks @rammi987. I can confirm the site was missing
.AddDeliveryApi(). Adding that has gotten the site running again.…thanks for the quick investigation efforts, @rammi987 👍
We’re seeing this as well upgrading from 12.0 to 12.1