Skip to content
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

Exception in BlazorWasm applications due to NullabilityInfoContext usage #102848

Closed
sebastienros opened this issue May 29, 2024 · 2 comments · Fixed by #102852
Closed

Exception in BlazorWasm applications due to NullabilityInfoContext usage #102848

sebastienros opened this issue May 29, 2024 · 2 comments · Fixed by #102852

Comments

@sebastienros
Copy link
Member

Description

This was introduced in #102499. This blocking runtime ingestion in ASP.NET for preview 5.

This exception is thrown when running a BlazorWasm application.

NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.

The BlazorWebAssembly SDK disabled the feature https://github.com/dotnet/sdk/blob/a304e06708d72c1be0d78e214366a2c7c601b5d8/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets#L49

This method should check NullabilityInfoContext.IsSupported is true before using calling NullabilityInfoContext.Create.

Reproduction Steps

Run a BlazorWebAssembly application like this one:

https://github.com/dotnet/aspnetcore/blob/release/9.0-preview5/src/Components/WebAssembly/testassets/StandaloneApp/StandaloneApp.csproj

Expected behavior

Application should not throw an exception when the System.Reflection.NullabilityInfoContext.IsSupported flag is false.

Actual behavior

An exception is thrown.

Regression?

Yes

Known Workarounds

Enable the System.Reflection.NullabilityInfoContext.IsSupported switch.

Configuration

No response

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 29, 2024
@sebastienros sebastienros added blocking-release and removed area-System.Reflection untriaged New issue has not been triaged by the area owner labels May 29, 2024
@jozkee jozkee added this to the 9.0.0 milestone May 29, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@jozkee
Copy link
Member

jozkee commented May 29, 2024

System.Reflection.NullabilityInfoContext.IsSupported is used by apps to trim nullability annotations, as @eiriktsarpalis mentioned offline, we could bail when the switch is set to false and process things like they were nullable-oblivious, but it feels odd that NullabilityInfoContext throws here rather than returning new NullabilityInfo { ReadState = NullabilityState.Unknown, WriteState = NullabilityState.Unknown }.

cc @buyaa-n @eerhardt

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants