Repository navigation
Description
Bug description
This only occurs when running a migration on Linux. Windows appears to be ok with this. I am currently testing this in WSL2 with the Ubuntu distro. When I run my test suite on WSL2 I get the PendingModelChangesWarning. I have added a migration and found that its a diacritic unicode character that isn't recognised as being a match. The output of the migration is shown in the code section.
I recognise that this isn't technically a dotnet ef bug, but I don't know how the diff occurs in order to fix it on my environment and would like to know a solution. Hopefully making this useful for someone else. I have gone through the other issues, but I cannot find a similar issue.
Your code
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace XXXX.Migrations
{
/// <inheritdoc />
public partial class Test : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "BusinessTypes",
keyColumn: "BusinessTypeId",
keyValue: 28,
column: "WebDescription",
value: "Caf�");
migrationBuilder.UpdateData(
table: "BusinessTypes",
keyColumn: "BusinessTypeId",
keyValue: 29,
column: "WebDescription",
value: "Caf� & bar");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "BusinessTypes",
keyColumn: "BusinessTypeId",
keyValue: 28,
column: "WebDescription",
value: "Café");
migrationBuilder.UpdateData(
table: "BusinessTypes",
keyColumn: "BusinessTypeId",
keyValue: 29,
column: "WebDescription",
value: "Café & bar");
}
}
}Stack traces
Verbose output
EF Core version
10.0.0
Database provider
No response
Target framework
No response
Operating system
Windows 11 & WSL2.0 Ubuntu
IDE
Visual Studio 2026 18.5.2
Activity
mike-jewell commentedon Apr 29, 2026
I'm not so sure it is the OS that is the issue....
I am able to create a file with a diacritic in it no problem:
TomasMoralesBarr commentedon Apr 29, 2026
Root Cause Analysis
This bug is caused by a Unicode normalization mismatch between Windows and Linux.
The character
éin"Café"can be represented in two valid Unicode forms:\u00E9écharacter — default on Windowse+\u0301eplus a combining accent — common on Linux/macOSWhen the migration snapshot is generated on Windows (NFC) and
HasPendingModelChanges()is later executed on Linux (NFD), EF Core detects a difference that does not semantically exist, triggering thePendingModelChangesWarningand scaffolding a corrupt/empty migration.Source of the Problem
The issue lives in
MigrationsModelDiffer.cs, in the seed data comparison logic:Equals()on strings performs a byte-by-byte (ordinal) comparison, so"Café"in NFC ≠"Café"in NFD, even though they are visually and semantically identical.Proposed Fix
The fix is small and self-contained (~5–10 lines in a single file). String values should be normalized to NFC before being compared, using .NET's built-in API:
This ensures that seed data comparison is OS-independent, regardless of the default Unicode normalization used by the underlying platform.
Immediate Workaround
While the official fix is not yet available, you can explicitly force NFC normalization in your
OnModelCreating. This guarantees that the value stored in both the model and the snapshot is always byte-for-byte identical across platforms:Optionally, you can define a small extension method to keep things clean if you have many strings:
TomasMoralesBarr commentedon Apr 29, 2026
I would like to work on a fix.
roji commentedon Apr 30, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Summary
This is a confirmed bug in EF Core's seed data comparison logic. When the same Unicode character (e.g.
é) is represented in NFC (precomposed: U+00E9) vs NFD (decomposed: U+0065 + U+0301) between the model snapshot and the current model, EF Core falsely detects a pending model change.Type: Bug
Area: area-migrations-seeding (already labeled correctly)
Root Cause
The seed data comparison in
MigrationsModelDiffer.csat line 2217 uses theProviderValueComparer, which for strings defaults to ordinal equality (==). Ordinal comparison is byte-sensitive and does not account for Unicode canonical equivalence — NFC"Café"(5 UTF-8 bytes:43-61-66-C3-A9) ≠ NFD"Café"(6 UTF-8 bytes:43-61-66-65-CC-81), even though they represent the identical logical string.Windows vs. Linux Behavior
The claim that "Windows is ok but Linux isn't" is likely a coincidence of how the source files were authored, not a runtime behavioral difference. Key findings:
object.Equals/string.==is ordinal and platform-independent — it would fail on both platforms given different normalization forms.The most likely scenario is:
HasData("Café")) was authored with one normalization form (likely depends on the editor/input method/OS used when typing).Regarding
StringComparisonas a FixI tested whether any
StringComparisonenum value handles NFC/NFD equivalence:OrdinalInvariantCultureCurrentCultureStringComparison.InvariantCulturedoes correctly treat NFC and NFD as equal, and does NOT introduce unwanted collapsing (e.g.ß≠ss, case is preserved). This is because the Unicode Collation Algorithm used by ICU/NLS inherently handles canonical equivalence.However, for a fix in EF Core I would still recommend explicit normalization to NFC before ordinal comparison rather than switching to culture-aware comparison, because:
MultilineEquals()normalizes line endings before ordinal comparison — the same pattern (normalize form, then compare ordinally) should be applied for Unicode normalization.A possible fix would normalize string values to NFC before comparison in the seed data diff path (around line 2217 and/or wherever
ProviderValueComparer.Equalsis called for seed data values).No Duplicates Found
No existing open or closed issues in the EF Core repo match this specific scenario.
roji commentedon Apr 30, 2026
I'm personally leaning in the direction of using InvariantCulture rather than calling Normalize() - that's exactly what it's there for, and I'm not sure why it would "subtly differ across .NET versions and ICU/NLS implementations" any more than Normailze(). But no strong feelings.
@AndriySvyryd assigning this and #38197 to you as it's in your area.
roji commentedon Apr 30, 2026
Additional AI note: why NFC normalization over
StringComparison.InvariantCultureInvariantCulturecomparison does more than handle canonical equivalence (NFC↔NFD) — it also ignores "default ignorable" characters like soft hyphen (U+00AD), zero-width space (U+200B), etc.:With explicit NFC normalization + ordinal comparison, only canonically equivalent representations are collapsed — nothing else. Characters that are distinct bytes in the database remain distinct in the comparison.
That said, the ignorable-character scenario is somewhat edge-case for typical seed data, so
InvariantCulturewould work for the common case and is simpler code. It's a judgment call on how defensively to code the fix.roji commentedon Apr 30, 2026
@AndriySvyryd just noting that we should keep change tracking in mind here too. In other words, if non-normalized string comparison affects string comparisons in HasData(), does it also affect change tracking in an adverse way? Should the two be aligned?
"Use InvariantCulture string comparer to handle NFC/NFD Unicode equiv…
Normalize Unicode strings from seed data before comparing
Normalize Unicode strings from seed data before comparing (dotnet#38617)