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

.NET 9 breaks ShouldSerializeXXX methods in data model (NullReferenceException) #59402

Closed
1 task done
arisewanggithub opened this issue Dec 9, 2024 · 7 comments
Closed
1 task done
Labels
Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Comments

@arisewanggithub
Copy link

arisewanggithub commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We are currently using .net 8 and we are upgrading to .net 9. But with the upgrade, our service can't start because some ShouldSerializeXXX methods throw NullReferenceException. e.g.
Image

And from stacktrace, I can see the ShouldSerializeXXX methods are called from here in namespace Newtonsoft.Json.Serialization:
Image

Microsoft.AspNetCore.Mvc.NewtonsoftJson has already been upgraded to 9.0.0
This works fine in .net 8 but breaks in .net 9

Expected Behavior

NullReferenceException should not be thrown when start the service

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.101

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Dec 9, 2024
@BrennanConroy
Copy link
Member

What makes this a .NET or ASP.NET Core issue? The method you're pointing at is part of Newtonsoft.Json.
https://github.com/JamesNK/Newtonsoft.Json/blob/9317d71ac5f08c354060bad2cd9bfe6ed5856294/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs#L1646

If you think it is an ASP.NET Core issue, please provide a minimal repro project.

@gfoidl gfoidl added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Dec 10, 2024
@arisewanggithub
Copy link
Author

WebApiTest.zip
I've created a minimum web service that can repro this. From the stack trace, I think the issue is triggered when NSwag OpenAPI documentation is generated on service startup. The same code works in .net 8 but not in .net 9.

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 10, 2024
@BrennanConroy
Copy link
Member

BrennanConroy commented Dec 10, 2024

Please provide the project as a github repo not a zip
https://github.com/dotnet/aspnetcore/blob/main/docs/repro.md#what-is-a-minimal-repro-project

@arisewanggithub
Copy link
Author

OK, here is the github repo link: https://github.com/arisewanggithub/dotnetissue59402

@martincostello
Copy link
Member

From the stack trace, I think the issue is triggered when NSwag OpenAPI documentation is generated on service startup

Maybe it's an NSwag issue?

@BrennanConroy
Copy link
Member

Yeah, this looks like an NSwag issue. Closing as I don't see anything from ASP.NET Core in the stack.

@arisewanggithub
Copy link
Author

OK, I created a new issue on NSWag for this: RicoSuter/NSwag#5065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Projects
None yet
Development

No branches or pull requests

4 participants