Skip to content

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

Closed
@arisewanggithub

Description

@arisewanggithub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions