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

Avoid nullref while trying to throw a more helpful exception. #55316

Conversation

StephenMolloy
Copy link
Member

Avoid nullref while trying to throw a more helpful exception.

The method checking for referential surrogates during deserialization
(ReplaceDeserializedObject) wants to throw a helpful exception when
it can't fix up references post-type-substitution. In order to actually be
helpful, avoid nullref-ing when one of the objects involved in the
replacement is null. Simply use the term "unknown type" instead.

Fixes #41465

Comment on lines 364 to 365
var oldType = (oldObj != null) ? DataContract.GetClrTypeFullName(oldObj.GetType()) : "unknown type";
var newType = (newObj != null) ? DataContract.GetClrTypeFullName(newObj.GetType()) : "unknown type";
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
var oldType = (oldObj != null) ? DataContract.GetClrTypeFullName(oldObj.GetType()) : "unknown type";
var newType = (newObj != null) ? DataContract.GetClrTypeFullName(newObj.GetType()) : "unknown type";
string oldType = (oldObj != null) ? DataContract.GetClrTypeFullName(oldObj.GetType()) : "unknown type";
string newType = (newObj != null) ? DataContract.GetClrTypeFullName(newObj.GetType()) : "unknown type";

Also, does "unknown type" need to come from a resx?

Copy link
Member

@mconnew mconnew left a comment

Choose a reason for hiding this comment

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

Please make the changes that @stephentoub requested. "Unknown Type" should be a string resource so that it gets translated.

@StephenMolloy StephenMolloy merged commit 0663b30 into dotnet:main Jul 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullReferenceException in XmlObjectSerializerReadContext.ReplaceDeserializedObject
4 participants