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

Blazor app - 8.0.1 AOT producing Json errors #98180

Closed
Sean4572435243 opened this issue Feb 8, 2024 · 4 comments
Closed

Blazor app - 8.0.1 AOT producing Json errors #98180

Sean4572435243 opened this issue Feb 8, 2024 · 4 comments

Comments

@Sean4572435243
Copy link

Description

I get this error underneath my function call

FAILURE: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair2[System.String,System.Collections.Generic.List1[System.String]] at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread ) --- End of stack trace from previous location --- at (and then my function stack)

This error does not appear when AOT is disabled, and I'm not using JsonSerializer for anything. In fact, I rolled my own serialization logic because I thought it was something related to the .net serializer.

What's really interesting, is if I just eat this error and continue, it doesn't happen again, so I'm purposely inciting and eating this error in my initialization now.

Reproduction Steps

Will be very time-consuming to reduce my project to a working sample. Let's pursue that if what I've provided isn't enough.

Expected behavior

no errors

Actual behavior

the indicated error

Regression?

There's nothing wrong with my code. It works perfectly when AOT is disabled. AOT breaks it.

Known Workarounds

Eat the initial errors, works great after that

Configuration

latest everything

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 8, 2024
@ghost
Copy link

ghost commented Feb 8, 2024

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

Issue Details

Description

I get this error underneath my function call

FAILURE: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair2[System.String,System.Collections.Generic.List1[System.String]] at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread ) --- End of stack trace from previous location --- at (and then my function stack)

This error does not appear when AOT is disabled, and I'm not using JsonSerializer for anything. In fact, I rolled my own serialization logic because I thought it was something related to the .net serializer.

What's really interesting, is if I just eat this error and continue, it doesn't happen again, so I'm purposely inciting and eating this error in my initialization now.

Reproduction Steps

Will be very time-consuming to reduce my project to a working sample. Let's pursue that if what I've provided isn't enough.

Expected behavior

no errors

Actual behavior

the indicated error

Regression?

There's nothing wrong with my code. It works perfectly when AOT is disabled. AOT breaks it.

Known Workarounds

Eat the initial errors, works great after that

Configuration

latest everything

Other information

No response

Author: Sean4572435243
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

Duplicate of dotnet/aspnetcore#52947

@eiriktsarpalis eiriktsarpalis marked this as a duplicate of dotnet/aspnetcore#52947 Feb 8, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Feb 8, 2024
@Sean4572435243
Copy link
Author

Sean4572435243 commented Feb 9, 2024

Not sure if it's the same issue. I agree under the hood, the deprecated serialization of KeyValuePair in 8.0 is the issue, but I'd like to add the following notes because I believe this shouldn't have generated the error in the first place.

I have:

var myBytes = new byte[] {234, 146, 62, 14};

The code:

var bytesSum = myBytes.Sum(b => b);

will trigger the exception indicated, whereas this alternate approach:

var bytesSum = myBytes[0] + myBytes[1] + myBytes[2] + myBytes[3];

works fine.

@Sean4572435243
Copy link
Author

And here's another example of strange AOT behavior eliciting this exception, once again by LINQ and 'not' directly using serialization or KeyValuePair. This code triggers the exception:

var myBytes = myInts.SelectMany(BitConverter.GetBytes).ToArray();

But this alternative approach works fine

var myBytes = new byte[myInts.Length * 4];
for (int i = 0; i < myInts.Length; i++)
    Buffer.BlockCopy(BitConverter.GetBytes(myInts[i]), 0, myBytes, i * 4, 4);

@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants
@eiriktsarpalis @Sean4572435243 and others