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

System.Net.Http.HttpRequestException is not marked as [Serializable] #42154

Closed
magole opened this issue Sep 12, 2020 · 16 comments
Closed

System.Net.Http.HttpRequestException is not marked as [Serializable] #42154

magole opened this issue Sep 12, 2020 · 16 comments
Labels
api-approved API was approved in API review, it can be implemented area-System.Net.Http
Milestone

Comments

@magole
Copy link

magole commented Sep 12, 2020

This issue is related to this issue.

Projects like Orleans require types and especially exceptions to be serializable. Most .NET Core exceptions are already marked as such.

The ask is to mark HttpRequestException as [Serializable] and add the requisite protected ctors.

@GrabYourPitchforks GrabYourPitchforks transferred this issue from dotnet/core Sep 12, 2020
@GrabYourPitchforks GrabYourPitchforks added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Serialization labels Sep 12, 2020
@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Sep 12, 2020

API proposal:

namespace System.Net.Http
{
    [Serializable] // ADD this attribute
    public class HttpRequestException
    {
        protected HttpRequestException(SerializationInfo info, StreamingContext context); // ADD this ctor
        public override void GetObjectData(SerializationInfo info, StreamingContext context); // OVERRIDE this method
    }
}

This is a request from the Orleans team and matches when we said we'd allow new serialization ctors to be added: (a) it must be an exception-derived type, and (b) the type must exist across both .NET Core and .NET framework. The HttpRequestException type meets both of these.

n.b. Full Framework does not expose the APIs being added here. The HttpRequestException type uses the "partial trust-compliant BinaryFormatter serialization" that was introduced in .NET 4, but that infrastructure does not exist in .NET Core. .NET Core only understands the normal Exception serialization pattern, so that is what's added by this API proposal. There is no plan to add these APIs back to this type in Full Framework. This also means that HttpRequestException instances serialized on Core cannot be deserialized on Full Framework, and vice versa. There is no plan to support this capability.

I'll create a separate issue to track allowing Exception objects to be serialized without using BinaryFormatter or other unsafe-style serialization tech.

@GrabYourPitchforks
Copy link
Member

Opened https://github.com/dotnet/designs/issues/158 to track creating safe Exception serialization tech.

@GrabYourPitchforks GrabYourPitchforks added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Sep 12, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Sep 13, 2020
@scalablecory
Copy link
Contributor

@dotnet/ncl

@scalablecory
Copy link
Contributor

@GrabYourPitchforks this class is not sealed, adding an interface is a breaking change no?

@GrabYourPitchforks
Copy link
Member

It's not a breaking compile-time change. It's potentially a breaking runtime change in that if somebody marked their subclassed type [Serializable] without also implementing ISerializable (which honestly would be very, very weird for an Exception to do), the serialized payload format would now change.

@GrabYourPitchforks
Copy link
Member

Oh, derp, of course the base type already implements the interface. I'll update the proposal.

@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Sep 15, 2020
@terrajobst
Copy link
Member

terrajobst commented Sep 15, 2020

Video

  • Seems fine per our guidance
  • We won't do this for all exception, but only for exceptions that exist in both .NET Framework and .NET Core
  • Specifically, we won't do this for .NET Core-only exceptions
  • And moving forward, we'll phase out BinaryFormatter anyways
namespace System.Net.Http
{
    [Serializable]
    public class HttpRequestException
    {
        protected HttpRequestException(SerializationInfo info, StreamingContext context);
        public override void GetObjectData(SerializationInfo info, StreamingContext context);
    }
}

@terrajobst terrajobst removed the untriaged New issue has not been triaged by the area owner label Sep 15, 2020
@ghost
Copy link

ghost commented Sep 17, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@karelz karelz added this to the 6.0.0 milestone Oct 2, 2020
@stephentoub
Copy link
Member

Whoever implements this will need to make sure that the type serializes/deserializes correctly in both directions between .NET Core and .NET Framework, otherwise it'll defeat the purpose of this. And to that end, a) there have been several new members added to HttpRequestException in .NET Core, so they'll need to be properly dealt with, and b) the implementation on .NET Framework uses the "safe serialization" mechanism, and I'm not sure that'll "just work".

@karelz karelz modified the milestones: 6.0.0, Future May 4, 2021
@deeprobin
Copy link
Contributor

@stephentoub You're welcome to assign me

@danmoseley
Copy link
Member

danmoseley commented Dec 21, 2021

@GrabYourPitchforks as this missed 6.0, and in 7.0 we expect to disable BinaryFormatter by default and the hypothetical replacement does not depend on ISerializable. is this still relevant?

I realize this package ships on .NET Framework as well, but as noted above, it must deserialize on .NET Core too.

@danmoseley
Copy link
Member

@GrabYourPitchforks thoughts?

@danmoseley
Copy link
Member

@GrabYourPitchforks ...

@GrabYourPitchforks
Copy link
Member

Spoke offline with Steve about this. Since the scenario of cross-serializing between netfx and netcore won't be supported, the "exceptions which exist on both platforms" rule of thumb really doesn't apply, since we really won't be able to support the scenario that rule of thumb was trying to drive at. I'm supportive of just closing this issue as won't-fix.

@danmoseley
Copy link
Member

#60600 (comment) mentioned by @bartonjs also describes the cross appdomain scenario. Are we consistent, and is our guidance clear? Or is cross appdomain not relevant here?

@stephentoub
Copy link
Member

That isn't relevant here.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 22, 2022
@karelz karelz modified the milestones: Future, 7.0.0 Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Net.Http
Projects
None yet
Development

No branches or pull requests

10 participants