Skip to content

NullReferenceException in System.Numerics.Vector.get_IsHardwareAccelerated() #128901

Closed

Description

@rolfbjarne

Description

We get a NRE like this in a number of our Mac Catalyst (only, not macOS) unit tests:

NullReferenceException
 at System.Numerics.Vector.get_IsHardwareAccelerated()
 at System.SpanHelpers.Fill[T](T& refData, UIntPtr numElements, T value)
 at System.Buffers.ProbabilisticMapState..ctor(ReadOnlySpan`1 values, Int32 maxInclusive)
 at System.Buffers.ProbabilisticWithAsciiCharSearchValues`1..ctor(ReadOnlySpan`1 values, Int32 maxInclusive)
 at System.Buffers.SearchValues.Create(ReadOnlySpan`1 values)
 at System.Text.Json.JsonReaderHelper..cctor()
 at System.Runtime.CompilerServices.InitHelpers.CallClassConstructor(Void* cctor, Void* instantiatingArg, Exception* pException)

Reproduction Steps

Important: use an x64 machine (this does not seem to repro on Rosetta).

git clone https://github.com/dotnet/macios --recurse-submodules
cd macios
git checkout darc-release/11.0.1xx-preview5-ac83f574-df9a-48c9-ab93-f3bcb3a825ba
git reset --hard 51283bed16305c25c2b6c19891d8e5a365e09c71
git cherry-pick f708cd61aa348284654db81c802b9362fbc54748
git cherry-pick 0e55db3f754412b770d9ba1c3e6d630ad56ae29a
git cherry-pick 58ead49e76836ff1462fabdd7a94cc4ab04c81fa
./configure --disable-all-platforms --enable-ios
make all -j8
make install -j8
cd tests/monotouch-test/dotnet/MacCatalyst
make clean build run-bare RID=maccatalyst-x64 RUN_ARGUMENTS='--test MonoTouchFixtures.CoreGraphics.PDFDocumentTest'

Note: it's possible to follow all the repro steps on any machine, and then finally copy the test app to an x64 machine to run it. The app is bin/Debug/net11.0-maccatalyst/maccatalyst-x64/monotouchtest.app - copy the entire directory and then run:

./monotouchtest.app/Contents/MacOS/monotouchtest --autoexit --autostart --test MonoTouchFixtures.CoreGraphics.PDFDocumentTest

Expected behavior

[...]
monotouchtest
MonoTouchFixtures
MonoTouchFixtures.CoreGraphics
MonoTouchFixtures.CoreGraphics.PDFDocumentTest
	[PASS] DataProvider
	[PASS] FromFile
	[PASS] FromUrl
MonoTouchFixtures.CoreGraphics.PDFDocumentTest : 41.4037 ms
MonoTouchFixtures.CoreGraphics : 41.4638 ms
MonoTouchFixtures : 41.6845 ms
monotouchtest : 44.1212 ms
EmbeddedResources
EmbeddedResources : 0.0391 ms
bindings-test
bindings-test : 0.0014 ms
Tests run: 3 Passed: 3 Inconclusive: 0 Failed: 0 Ignored: 0
AutoRun (): completed test run on main thread
Exiting test run with success

Actual behavior

[...]
monotouchtest
MonoTouchFixtures
MonoTouchFixtures.CoreGraphics
MonoTouchFixtures.CoreGraphics.PDFDocumentTest
	[FAIL] DataProvider : System.NullReferenceException : Object reference not set to an instance of an object.
		   at System.Numerics.Vector.get_IsHardwareAccelerated()
		   at System.SpanHelpers.Fill[T](T& refData, UIntPtr numElements, T value)
		   at System.String.Ctor(Char c, Int32 count)
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.Dump(StringBuilder sb, Int32 indentation, CGPDFDictionary dict) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 129
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.DumpPdf(CGPDFDocument doc) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 152
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.CheckTamarin(CGPDFDocument pdf) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 65
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.DataProvider() in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 24
		   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
		   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
	[FAIL] FromFile : System.NullReferenceException : Object reference not set to an instance of an object.
		   at System.Numerics.Vector.get_IsHardwareAccelerated()
		   at System.SpanHelpers.Fill[T](T& refData, UIntPtr numElements, T value)
		   at System.String.Ctor(Char c, Int32 count)
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.Dump(StringBuilder sb, Int32 indentation, CGPDFDictionary dict) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 129
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.DumpPdf(CGPDFDocument doc) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 152
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.CheckTamarin(CGPDFDocument pdf) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 65
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.FromFile() in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 32
		   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
		   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
	[FAIL] FromUrl : System.NullReferenceException : Object reference not set to an instance of an object.
		   at System.Numerics.Vector.get_IsHardwareAccelerated()
		   at System.SpanHelpers.Fill[T](T& refData, UIntPtr numElements, T value)
		   at System.String.Ctor(Char c, Int32 count)
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.Dump(StringBuilder sb, Int32 indentation, CGPDFDictionary dict) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 129
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.DumpPdf(CGPDFDocument doc) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 152
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.CheckTamarin(CGPDFDocument pdf) in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 65
		   at MonoTouchFixtures.CoreGraphics.PDFDocumentTest.FromUrl() in /Users/rolf/work/dotnet/macios/11.0.1xx/macios/tests/monotouch-test/CoreGraphics/PDFDocumentTest.cs:line 41
		   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
		   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
MonoTouchFixtures.CoreGraphics.PDFDocumentTest : 53.9463 ms
MonoTouchFixtures.CoreGraphics : 53.9706 ms
MonoTouchFixtures : 54.0773 ms
monotouchtest : 54.7475 ms
EmbeddedResources
EmbeddedResources : 0.0059 ms
bindings-test
bindings-test : 0.0015 ms
Tests run: 3 Passed: 0 Inconclusive: 0 Failed: 3 Ignored: 0
AutoRun (): completed test run on main thread
Exiting test run with code 1

Regression?

Yes

Known Workarounds

No response

Configuration

This started happening in the latest .NET 11 maestro bump:

Other information

Might be related to #128898.

Activity

  1. added
    untriaged
    on Jun 2, 2026
  2. added
    os-ios
    and removed
    untriaged
    on Jun 2, 2026
  3. self-assigned this
    on Jun 2, 2026
  4. added this to the 11.0.0 milestone on Jun 2, 2026
  5. dotnet-policy-service commented on Jun 2, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
    See info in area-owners.md if you want to be subscribed.

  6. dotnet-policy-service commented on Jun 2, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg
    See info in area-owners.md if you want to be subscribed.

  7. kotlarmilos commented on Jun 4, 2026

    @kotlarmilos
    Member

    @rolfbjarne can you try the failing test on x64 (if you have a device) with DOTNET_MaxVectorTBitWidth=128 set?

    The CoreCLR interpreter only handles 128-bit Vector, but on x64 with AVX2 it ends up picking 256-bit and mishandles it, which is where the NRE in Vector.get_IsHardwareAccelerated comes from. The cap that should force it back to 128-bit only runs when InterpMode == 3, but on mobile everything is interpreted at InterpMode == 0, so the cap never fires. On arm64 it doesn't matter since Vector is always 128-bit there.

    I traced the runtime commits in the bump (013ca46 - 518c8cb) and the relevant code is identical. The only thing that is relevant is that String.Ctor -> SpanHelpers.Fill -> Vector.IsHardwareAccelerated started being run through the x64 CoreCLR interpreter.

    /cc: @davidwrighton

  8. rolfbjarne commented on Jun 4, 2026

    @rolfbjarne
    MemberAuthor

    @rolfbjarne can you try the failing test on x64 (if you have a device) with DOTNET_MaxVectorTBitWidth=128 set?

    Yes, that works.

  9. added a commit that references this issue on Jun 8, 2026
    fc3e8ea
  10. locked and limited conversation to collaborators on Jul 9, 2026
  11. added a commit that references this issue on Jul 15, 2026
    d1f141b
  12. added a commit that references this issue on Jul 22, 2026
    53236d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions