Open Iztharoth opened 10 months ago
Seems like the same issue as https://github.com/dotnet/efcore/issues/28022
Whoops wrong button š„²
Note for triage: I am able to reproduce this. Also fails for EF7 on .NET 8 and EF7 on .NET 7, so not a regression.
I did run into this same issue, and what I did was to comment out this and migrations succeeded
//public ArchiveContext(DbContextOptions<ArchiveContext> options)
//: base(options) { }
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[ArchiveDb.ArchiveContext]' while attempting to activate 'ArchiveDb.ArchiveContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time
And if you add a parameterless constructor to you dbcontext then migrations work also
public ArchiveContext(DbContextOptions<ArchiveContext> options) : base(options) { }
public ArchiveContext() { }
I have the same problem, I added a parameterless constructor and it still didn't work.
Project --> Blazor Web App
I have the same problem when using Microsoft.Extensions.DependencyInjection
I also have the same problem. Please fix.
I have the same problem in my Win UI 3 application which I generated by using the Template Studio plugin in VS 2022. My application requires the EF Core 7.0.17 with SQLite and the whole solution targets the net7.0-windows10.0.19041.0
.
I had to quite outsmart the process by removing the hosting NuGet package Microsoft.Extensions.Hosting
as proposed above and commenting out quite a large portion of the Win UI 3 app code that depended on it to get a migration created. It also required me to override the OnConfiguring method in my DB context to specify that the database provider is SQLite with the provided connection string name.
Overall, it was not an easy and pleasant process and I hope I will not be required to repeat that anytime soon.
I'm also facing the same problem. Using a parameterless constructor does not fix the problem.
Issue still exists
I had same problem. I had an ASP.Net React project and I had tried to create migration but it didn't work. I had had 2 startup project one for React one and for API and I had tried choosing only API project and it's worked.
I currently am having this problem while trying to run db migration via github actions.
And if you add a parameterless constructor to you dbcontext then migrations work also
public ArchiveContext(DbContextOptions<ArchiveContext> options) : base(options) { } public ArchiveContext() { }
Adding the empty constructor resolved the issue for me too. Thank you. I spent a whole day on this one :|
https://github.com/dotnet/efcore/pull/34082 should improve some cases starting with 9.0.0-rc1 when IDesignTimeDbContextFactory
is implemented. But in general, EF tooling doesn't support platform-specific apps and we recommend using Migrations projects
The first sentence of the linked page is funny in this context: You may want to store your migrations in a different project than the one containing your DbContext
- should read something like You cannot store your migrations in a platform-specific project.
.
Hi Folks,
I am building a WinUI 3 app and want to use SQLite using ef core. When using the Microsoft.Extensions.Hosting package, the
dotnet ef migrations add
command doesn't give any errors but also doesn't give or log any errors. When removed from the .csproj file the and use Microsoft.Extensions.DependencyInjection, the migration is created without any problems.I created a small sample 3 app with ef core. In the current state of the project within App1.zip is Microsoft.Extensions.Hosting included.
Am I missing something?
How to reproduce?
dotnet ef migrations add InitialCreate -v
dotnet clean
dotnet ef migrations add InitialCreate -v
againCode
Project zip
App1.zip
The constructor in the App.xaml.cs.
Context factory
Output
Using Microsoft.Extensions.DependencyInjection
Using Microsoft.Extensions.Hosting
Include provider and version information
EF Core version: Database provider: Microsoft.EntityFrameworkCore.SQLite (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: .NET 8 Operating system: Windows 11 IDE: Visual Studio 2022 17.9 Preview