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

Add cross-platform exception serialization support #7222

Conversation

Arkatufus
Copy link
Contributor

Fixes #7215

Changes

Embed TypeForwardedFromAttribute data inside the wire format so we can map System.Private.Corlib to mscorlib types.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

Self review

@@ -82,6 +83,11 @@ public Proto.Msg.ExceptionData ExceptionToProtoNet(Exception exception)
message.StackTrace = exception.StackTrace ?? "";
message.Source = exception.Source ?? "";
message.InnerException = ExceptionToProto(exception.InnerException);

var forwardedFrom = exceptionType.GetCustomAttribute<TypeForwardedFromAttribute>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.NET standard introduced this attribute to mark a type as being moved from a different assembly

Copy link
Member

Choose a reason for hiding this comment

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

Wow, that would have been good to know a long time ago lol

Comment on lines +123 to +127
if (exceptionType is null && proto.TypeForwardedFrom != string.Empty)
{
var typeName = $"{proto.TypeName[..proto.TypeName.IndexOf(',')]}, {proto.TypeForwardedFrom}";
exceptionType = Type.GetType(typeName);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retry type loading with a different assembly name, if the type was marked as moved from an older assembly name

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@@ -69,6 +69,7 @@ message ExceptionData {
string source = 4;
ExceptionData innerException = 5;
map<string, Payload> customFields = 6;
string typeForwardedFrom = 7;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a single entry in the .proto file

@Arkatufus
Copy link
Contributor Author

Limiting the blast radius of this change to remoting ExceptionData (de)serialization, we're not applying this technique to all of our serialization pipeline

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +123 to +127
if (exceptionType is null && proto.TypeForwardedFrom != string.Empty)
{
var typeName = $"{proto.TypeName[..proto.TypeName.IndexOf(',')]}, {proto.TypeForwardedFrom}";
exceptionType = Type.GetType(typeName);
}
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb
Copy link
Member

Discussed with @Arkatufus - we're gonna add a repro to this before we merge it.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) June 3, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System messages containing BCL exceptions fail to deserialize on netfx when serialized on net5+/.net core
2 participants