Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

JsonSerializer throws exception in Blazor Web App .NET 8, when AOT is enabled

$
0
0

I am getting this exception in my Blazor Web App, whenever i try to use JsonSerializer while AOT is enabled. I get the exception when running in debug mode, which i find strange

System.InvalidOperationException: 'Reflection-based serialization hasbeen disabled for this application. Either use the source generatorAPIs or explicitly configure the'JsonSerializerOptions.TypeInfoResolver' property.'

Steps to reproduce my problem:

Create a Blazor Web App (WebAssembly) with .NET 8. Got to project properties and enable AOT

enter image description here

Goto Home.razor and add this code, so we trigger the use of System.Text.Json.JsonSerializer

@code{    protected override void OnInitialized()    {        var test = System.Text.Json.JsonSerializer.Serialize("Hello World");    }}

Now run the project in debug mode. When it tries to serialize, i get this exception


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>