Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add SwitchExpressionException #34954

Merged
merged 7 commits into from
Feb 8, 2019

Conversation

maryamariyan
Copy link
Member

Fixes: #33284

cc: @danmosemsft, @ViktorHofer

@maryamariyan maryamariyan self-assigned this Jan 30, 2019
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(UnmatchedValue), UnmatchedValue, typeof(object));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the type of UnmatchedValue isn't serializable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of exception serialization in .NET Core is basically telemetry (viz Azure Backup that requested we bring it back). So what I suggest is attempting to serialize, and if there's a SerializationException, create some kind of potentially useful string (using ToString and possibly ellipses?) and stuff that in there instead.

Copy link
Member

@danmoseley danmoseley Jan 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW if we think that's the right approach, then we should open an issue to make the same fix to ArgumentOutOfRangeException which serializes a private field of arbitrary type. In the .NET Core world, it's more likely that's not in fact binary serializable and since most exceptions aren't serialized most of the time, it wouldn't necessraily be noticed for a while.

Similar for RuntimeWrappedException and a few others. In fact serailization of XmlSchemaValidationException seems always broken - it serializes an object that looks like it can be (maybe always is) an XmlNode, which we don't support serializing. BinaryFormatterTestData tests a constructor overload that doesn't set this object.

@ViktorHofer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what I suggest is attempting to serialize

We probably don't need to actually attempt to serialize, but could instead check obj.GetType().IsSerializable.

Regardless, your suggestion for what to do if it's false sounds reasonable: ToString() it and treat that as the UnmatchedValue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the pattern to use? i.e. where should I be checking for UnmatchedValue.GetType().IsSerializable?

Copy link
Member

@jkotas jkotas Feb 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other end of the spectrum, the matched item can be a really big serializable object graph. You can end up with megabytes of serializable payload by accident.

If we think about the exception binary serialization should be optimized for telemetry, we may want to always convert the object to string to have a better chance for a reasonably sized payload.

The binary serialization of exception stack trace is handled in similar way. The stacktrace is converted to string for binary serialization because of the elements that it is constructed from are not binary-serialization friendly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case ToString at least gives me the type name. Im thinking of how many times had to diagnose something with only the exception details in a log or bug report. That has made me quite biased towards including any potentially useful information. @stephentoub what are your thoughts? We seem to be having the same discussion in the linked issue 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunjvs any thoughts, I believe you were or first customer for exception serialization..? See #35041

Always ToString might work although it could be worse if ToString is not usefully implemented on the type.

Copy link
Member

@jkotas jkotas Feb 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am all for having the right level of detail in ToString.

I just do not think we should spending any cycles on trying to make binary serialization better in creative ways. Binary serialization is a dead end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryamariyan please go ahead and submit without the IsSerializable check, and we can have this discussion in #35041

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the contructors as specified by Immo.

@maryamariyan
Copy link
Member Author

@dotnet-bot test OSX x64 Debug Build

@dotnet-bot test UWP CoreCLR x64 Debug Build

@maryamariyan
Copy link
Member Author

@dotnet/dnceng UWP CoreCLR x64 Debug Build failure seems unrelated to change in PR:

Logs show

- FAILED 0x80080008 (Object server is stopping when OLE service contacts it
...
- 'XUnitRunnerUap' is not recognized as an internal or external command, 

For

System.Composition.Convention.Tests
System.Runtime.CompilerServices.Unsafe.Tests
System.Xml.Linq.Axes.Tests

@ViktorHofer
Copy link
Member

That error is discussed here: #35142

@danmoseley
Copy link
Member

CI was previously green, overall this was completely tested

@danmoseley danmoseley merged commit 3685052 into dotnet:master Feb 8, 2019
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
@maryamariyan maryamariyan deleted the SwitchExpressionException-2 branch May 8, 2019 22:10
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add SwitchExpressionException

Fixes: dotnet/corefx#33284

* Apply PR feedbacks

* Type just added to .net core 3.0

* quick cleanup

* Add test in BinaryFormatterTestData

* Updated the APIs for SwitchExpressionException

* Remove IsSerializable condition


Commit migrated from dotnet/corefx@3685052
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants