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

Support for JsonSerializer.Context when StreamingContext is removed #2953

Open
jdom opened this issue May 15, 2024 · 3 comments
Open

Support for JsonSerializer.Context when StreamingContext is removed #2953

jdom opened this issue May 15, 2024 · 3 comments

Comments

@jdom
Copy link
Contributor

jdom commented May 15, 2024

Since the StreamingContext type is Obsolete in .NET 8, is there a future plan for supporting a serialization context in the future?
StreamingContext was used in the BinaryFormatter infrastructure, which is going away, although Newtonsoft.Json uses this type for non-BinaryFormatter purposes.
The current workaround is to suppress the warning when using the JsonSerializer.Context property (when newing up StreamingContext actually), but it's not ideal.

If I read the BinaryFormatter obsoletion roadmap correctly, the type will not be removed in future versions (hopefully), so it might not be completely blocking given the workaround, but it's still worth some consideration.

@elgonzo
Copy link

elgonzo commented May 15, 2024

EDIT: Oh, never mind, my apologies. Ignore my comment please, i didn't notice you're a Microsoft guy...

> is there a future plan for supporting a serialization context in the future?

In my opinion, since quite a while already Newtonsoft.Json is basically a legacy library in maintenance mode, with System.Text.Json being the modern .NET json serializer that is in active development and part of the .NET BCL. Don't get you hopes up for Newtonsoft.Json receiving any noteworthy new features. If you need to maintain Newtonsoft.Json in an existing project, the workaround is (and quite likely will remain in the future) suppression of the SYSLIB0050 obsoletion warning for the StreamingContext ctor's.

@jdom
Copy link
Contributor Author

jdom commented May 16, 2024

Thanks @elgonzo , I think your opinion is valid, as I expected this too as a way to mark this issue as by design, if we believe we won't be blocked by it in the future.
I do work at Microsoft, but I'm not in the .NET team, so for this issue I'm just a random consumer of the library.

@markm77
Copy link

markm77 commented Aug 31, 2024

I also get warnings in .NET 8 for code like:

jsonSerializerSettings.Context =
    new StreamingContext(
        StreamingContextStates.All,
        optionsDict);

Warnings are:

Warning SYSLIB0050 : 'StreamingContextStates' is obsolete: 'Formatter-based serialization is obsolete and should not be used.' (https://aka.ms/dotnet-warnings/SYSLIB0050)
Warning SYSLIB0050 : 'StreamingContext.StreamingContext(StreamingContextStates, object?)' is obsolete: 'Formatter-based serialization is obsolete and should not be used.' (https://aka.ms/dotnet-warnings/SYSLIB0050)

Will this code break in .NET 9?

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