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
[wasm] R2R: NullReferenceException casting a null interface-call result to a reference-type generic parameter #131635
On browser-wasm (CoreCLR) with PublishReadyToRun, a shared-generic method that casts the null result of an interface call to its reference-type generic parameter throws NullReferenceException instead of returning null.
This breaks Blazor WebAssembly startup on CoreCLR, because ServiceProviderServiceExtensions.GetService<T>() is (T?)provider.GetService(typeof(T)) and throws when the requested service is not registered.
Repro
usingSystem;interfaceIProv{object?Get(Typet);}sealedclassEmptyProv:IProv{publicobject?Get(Typet)=>null;}classProgram{staticT?GetFrom<T>(IProvp)=>(T?)p.Get(typeof(T));staticvoidMain(){varp=newEmptyProv();Console.WriteLine(p.Get(typeof(IComparable))isnull);// True (OK)Console.WriteLine(GetFrom<IComparable>(p));// NullReferenceException under wasm R2R}}
GetFrom<T> must be ReadyToRun-compiled and instantiated over a reference type (shared __Canon). Interpreted execution returns null as expected.
Expected
GetFrom<IComparable>(p) returns null (casting a null reference to a reference type is null).
This is the underlying story, it prevents Di in Blazor from starting the app.
NullReferenceException: Arg_NullReferenceException
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetComponentActivatorOrDefault(IServiceProvider)
at Microsoft.AspNetCore.Components.RenderTree.Renderer..ctor(IServiceProvider, ILoggerFactory)
at Microsoft.AspNetCore.Components.RenderTree.WebRenderer..ctor(IServiceProvider, ILoggerFactory, JsonSerializerOptions, JSComponentInterop)
at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer..ctor(IServiceProvider, ResourceAssetCollection, ILoggerFactory, JSComponentInterop, Boolean )
at Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHost.RunAsyncCore(CancellationToken, WebAssemblyCultureProvider )
at _7_blazor_coreclr.Program.Main(String[] args)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions)
blazor.webassembly.js:1 Uncaught (in promise) Error: System.NullReferenceException: Arg_NullReferenceException
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1, JsonReaderOptions, MetadataDb&, StackRowStack&)
at System.Text.Json.JsonDocument.ParseUnrented(ReadOnlyMemory`1, JsonReaderOptions, JsonTokenType , Boolean )
at System.Text.Json.JsonDocument.TryParseValue(Utf8JsonReader&, JsonDocument& , Boolean, Boolean, Boolean )
at System.Text.Json.Serialization.Converters.JsonElementConverter.Read(Utf8JsonReader&, Type, JsonSerializerOptions)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& , Boolean& )
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader&, T& , JsonSerializerOptions, ReadStack&)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader&, ReadStack&)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader&, ReadStack&)
at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader&, JsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader&, Type , JsonSerializerOptions )
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments(JSRuntime, String, String, Type[])
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime, DotNetInvocationInfo& , IDotNetObjectReference, String)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime, DotNetInvocationInfo, String )
at E.endInvokeDotNetFromJS (http://localhost:52646/_framework/blazor.webassembly.js:1:4521)
at Object.On [as endInvokeDotNetFromJS] (http://localhost:52646/_framework/blazor.webassembly.js:1:80976)
at http://localhost:52646/_framework/dotnet.runtime.0z4f63phum.js:4:28947
at Object.Gt [as invokeJSImportST] (http://localhost:52646/_framework/dotnet.runtime.0z4f63phum.js:4:28700)
at _SystemInteropJS_InvokeJSImportST (http://localhost:52646/_framework/dotnet.native.2t5mn09wlw.js:1:81384)
at http://localhost:59905/_framework/System.Runtime.InteropServices.JavaScript.wnjkmu9es4.wasm:wasm-function[31]:0x955a
at http://localhost:59905/_framework/Microsoft.JSInterop.WebAssembly.ybbllj6kmb.wasm:wasm-function[13]:0x369d
at http://localhost:59905/_framework/dotnet.native.rdxgseajyb.wasm:wasm-function[7486]:0x2b6185
at http://localhost:59905/_framework/dotnet.native.rdxgseajyb.wasm:wasm-function[1447]:0x7c09c
at http://localhost:59905/_framework/dotnet.native.rdxgseajyb.wasm:wasm-function[489]:0x22410
Activity
dotnet-policy-service commentedon Jul 31, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jul 31, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
pavelsavara commentedon Jul 31, 2026
This is the underlying story, it prevents Di in Blazor from starting the app.
pavelsavara commentedon Jul 31, 2026
cc @davidwrighton @AndyAyersMS
pavelsavara commentedon Jul 31, 2026
probably yet another exhibition of the same issue
AndyAyersMS commentedon Jul 31, 2026
I have a fix, should have a PR up soon.
The extra "SP" arg prepending to managed calls is tripping up some logic in the JIT.
JIT: use user arg indices when reading call args (#131661)