-
Notifications
You must be signed in to change notification settings - Fork 8
Upgrade to .NET 10.0 and update NuGet packages #823
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
Changes from 3 commits
69f906d
5c0a65a
a367dc9
0924c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,22 +16,33 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) | |||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| builder.ConfigureServices(services => | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| ServiceDescriptor? descriptor = services.SingleOrDefault( | ||||||||||||||||||||||||||||||
| d => d.ServiceType == | ||||||||||||||||||||||||||||||
| typeof(DbContextOptions<EssentialCSharpWebContext>)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Remove the existing DbContext and related services | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| // Remove the existing DbContext and related services | |
| // Remove the primary DbContextOptions registration for EssentialCSharpWebContext |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filtering logic using Name.Contains("DbContextOptions") is fragile and could inadvertently remove services unrelated to EF Core. This string-based matching could match types that happen to have "DbContextOptions" in their name. Consider a more precise approach such as checking for specific known types like DbContextOptions<TContext>, IDbContextOptions, or filtering by namespace (e.g., types from Microsoft.EntityFrameworkCore).
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Add SQLite DbContext without using the global service provider" but the code in lines 47-52 still uses BuildServiceProvider() to create a service provider and initialize the database. The comment may be misleading - consider clarifying that this refers to the DbContext options not using a cached/global service provider, while database initialization still requires building a temporary service provider.
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Disable service provider caching to avoid shared state in EF Core 10" but doesn't explain why this is necessary or the implications. Consider expanding this comment to explain the specific EF Core 10 behavior change that necessitates this workaround, and any potential performance impact of disabling caching.
| // Disable service provider caching to avoid shared state in EF Core 10 | |
| // EF Core 10 change: DbContextOptions now participate more aggressively in internal | |
| // service provider caching so that model- and provider-specific services can be reused | |
| // across contexts. In this test setup we create many WebApplicationFactory instances that | |
| // all share the same in-memory SQLite connection. If EF Core caches the internal service | |
| // provider globally, state for one test run (e.g., model metadata, conventions, and | |
| // provider services) can be reused by another, causing "multiple providers" errors and | |
| // flaky tests due to unexpected shared state between factories. | |
| // | |
| // Disabling service provider caching forces EF Core to build a fresh internal service | |
| // provider for each DbContextOptions instance, isolating tests at the cost of a small | |
| // per-context startup overhead. This trade-off is acceptable for integration tests, but | |
| // should generally be avoided in production code where the additional allocations and | |
| // startup cost could impact performance. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "9.0.101", | ||
| "version": "10.0.100", | ||
| "rollForward": "latestMinor" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot do we need these changes?
And also the changes in WebApplicationFactory.cs? Can we just make sure we only have minimal changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
WarningsNotAsErrorsin Directory.Build.props is necessary because:NU1902/NU1903: .NET 10 introduced stricter NuGet audit that treats transitive package vulnerabilities as errors when
TreatWarningsAsErrorsis enabled. These vulnerabilities are in old design-time dependencies (Microsoft.AspNetCore.Mvc 1.0.3) pulled in by Microsoft.VisualStudio.Web.CodeGeneration.Design 10.0-rc.1. Without this,dotnet restorefails.CA1873: New .NET 10 analyzer with 21 instances across the codebase for logging performance. Without suppression,
dotnet buildfails.The WebApplicationFactory changes are necessary for EF Core 10 - without
EnableServiceProviderCaching(false), tests fail with "multiple database providers registered" error.Options:
Which approach would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we upgrade the package to recent enough that it is compatible and doesn't have transitive vulnerabilities? @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partially resolved in 0924c9b. I removed Microsoft.VisualStudio.Web.CodeGeneration.Design (RC version) which was only needed for scaffolding and reduced some vulnerabilities.
However, the remaining NU1902/NU1903 warnings are from Microsoft.AspNetCore.Mvc.Testing 10.0.0 (stable, not RC). This Microsoft package has transitive dependencies on old Microsoft.AspNetCore.Mvc 1.0.3 packages with known vulnerabilities. This is a Microsoft package issue, not something we can upgrade - we're already using the latest stable version (10.0.0).
The WarningsNotAsErrors for NU1902/NU1903 is still necessary to prevent build failures from these Microsoft package issues. The WebApplicationFactory changes are also still necessary for EF Core 10 compatibility.