You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.NET 11.0.0: Enum.Equals with a null Nullable<TEnum> argument throws NullReferenceException (fix #133826 not in release/11.0) #137270
On .NET 11.0.0, enumValue.Equals(nullableEnum) throws NullReferenceException when the nullable is null, in fully optimized code. It should return false, and does on .NET 10.
This is #133817. It was fixed in main by #133826 (milestone 12.0.0), but the fix is not in release/11.0, so the 11.0.0 GA runtime ships with the bug. gtFoldExprCall on release/11.0 still discards the non-null result for the argument (bool isNonNull; // Unused here.).
Could #133826 be backported to release/11.0 for servicing? #134898 (shared-generic enum folding, #134890) touches the same check and is also missing there.
dotnet build -c Release, then DOTNET_TieredCompilation=0 dotnet bin/Release/net11.0/repro.dll
dotnet publish -c Release -r <rid> -p:PublishAot=true, then run the native executable
Expected behavior
False
Actual behavior
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Program.<<Main>$>g__Test|0_0(E x, Nullable`1 y)
Tier-0 code and NativeAOT Debug builds return False.
Regression?
Yes. .NET 10 returns False with the same project, both NativeAOT and JIT with DOTNET_TieredCompilation=0. #133817 attributes it to #122779.
Known Workarounds
Avoid passing a Nullable<TEnum> to Enum.Equals(object); compare with == or object.Equals(a, b) instead. That only helps in code you own.
Configuration
.NET SDK 11.0.100, runtime 11.0.0 (11.0.26.53018)
macOS arm64 (JIT and NativeAOT); also seen on linux-x64 NativeAOT
Other information
A real-world hit: Testcontainers.Kafka 4.16.0 KafkaBuilder.Build() evaluates v.Vendor.Equals(DockerResourceConfiguration.Vendor) with a null KafkaVendor?, so every Kafka container build throws under .NET 11 NativeAOT:
System.NullReferenceException: Object reference not set to an instance of an object.
at Testcontainers.Kafka.KafkaBuilder.<>c__DisplayClass22_0.<Build>b__0(IKafkaVendorConfiguration v)
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1, Func`2, Boolean&)
at Testcontainers.Kafka.KafkaBuilder.Build()
The same code can fail under the JIT once the method is optimized.
Found while moving Dekaf's NativeAOT tests to .NET 11.
Adding reach data in case it helps with the servicing decision: this also breaks PDF generation with iText and one path in the Open XML SDK, so it is not limited to Testcontainers.
Same shape as the issue (box Nullable<TEnum> → constrained. TEnum → callvirt Object::Equals(Object) with a null nullable), hit inside widely used libraries. Standalone console harness, Release, Windows x64, same binaries on both runtimes:
Library call
Package
10.0.15
11.0.0, DOTNET_TieredCompilation=0
11.0.0, default tiering
Paragraph.SetFixedLeading / SetMultipliedLeading
itext 9.6.0
0 throws
NRE on every call, from call 1
NRE from about call 10,000
HtmlConverter.ConvertToPdf with a <ul> (top frame UlOlTagCssApplier.Apply)
itext.pdfhtml 6.3.2
0 throws
NRE on every call, from call 1
NRE from about call 325
Laying out a Document with a Paragraph and a Table (top frame LineRenderer.Layout)
itext 9.6.0
0 throws
NRE on every call, from call 1
NRE from about call 1,000
Canvas.ShowTextAligned(Paragraph, ...) on an existing PDF
itext 9.6.0
0 throws
NRE on every call, from call 1
NRE from about call 1,000
SpreadsheetDocument.ChangeDocumentType on a freshly opened package (DocumentType not read yet)
DocumentFormat.OpenXml 3.1.1 and 3.5.1
0 throws
NRE on every call, from call 1
NRE from about call 7,000
System.NullReferenceException: Object reference not set to an instance of an object.
at iText.Layout.Element.Paragraph.SetFixedLeading(Single leading)
What makes this hard to live with in production: with default tiering the calls succeed until the method is promoted to tier 1, so a short test run passes and a long-running server starts failing later. An IL scan of itext 9.6.0 + itext.pdfhtml 6.3.2 finds 32 call sites with this shape, so we cannot work around it call by call, and we are holding our .NET 11 upgrade for it.
A backport of #133826 to release/11.0 would unblock us. Happy to run the harness against a candidate build if that is useful.
Activity
dotnet-policy-service commentedon Nov 10, 2026
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Nov 10, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JOnysko commentedon Nov 11, 2026
Adding reach data in case it helps with the servicing decision: this also breaks PDF generation with iText and one path in the Open XML SDK, so it is not limited to Testcontainers.
Same shape as the issue (
box Nullable<TEnum>→constrained. TEnum→callvirt Object::Equals(Object)with a null nullable), hit inside widely used libraries. Standalone console harness, Release, Windows x64, same binaries on both runtimes:DOTNET_TieredCompilation=0Paragraph.SetFixedLeading/SetMultipliedLeadingHtmlConverter.ConvertToPdfwith a<ul>(top frameUlOlTagCssApplier.Apply)Documentwith aParagraphand aTable(top frameLineRenderer.Layout)Canvas.ShowTextAligned(Paragraph, ...)on an existing PDFSpreadsheetDocument.ChangeDocumentTypeon a freshly opened package (DocumentTypenot read yet)What makes this hard to live with in production: with default tiering the calls succeed until the method is promoted to tier 1, so a short test run passes and a long-running server starts failing later. An IL scan of itext 9.6.0 + itext.pdfhtml 6.3.2 finds 32 call sites with this shape, so we cannot work around it call by call, and we are holding our .NET 11 upgrade for it.
A backport of #133826 to
release/11.0would unblock us. Happy to run the harness against a candidate build if that is useful.AndyAyersMS commentedon Nov 11, 2026
We have a second report of this in #137382.
I have started a backport.
[release/11.0] Fix Enum.Equals folding for nullable boxed arguments (#…
Beta.4: the Kafka fixtures name their vendor, and the suites build un…
Beta.4: the Kafka fixtures name their vendor, and the suites build un…