Skip to content

Conversation

@StephenMolloy
Copy link
Member

@StephenMolloy StephenMolloy commented Aug 11, 2022

Fixes #68659

When nullable annotations were added to System.Xml, the return type of XmlSerializer.FromMappings() was not annotated. Mistakenly. While I believe it is true that we generate an XmlSerializer for every mapping passed into the method in the runtime-generated-serializer case, when drawing serializers from a pre-generated serializer assembly... if the assembly doesn't have a matching serializer for the mapping, we don't generate one. Ideally the pre-gen assembly and list of mappings in use are under the control of the same project/team/application or whatever, so there is a serializer for every mapping. But "ideally" isn't always the case. And in this code, the mappings array and the pregenerated serializer assembly are in theory from different sources and may not match up. And when that happens, we need to return a null entry in the serializer array - because there is the expectation that positions in the returned serializer array match up with the corresponding position in the mapping array passed in.

That's all a long-winded way of saying that we might return null serializer entries in the pre-gen case. That's has always been the case and it is expected. The nullable notation missed that, and as a result, we missed this potential null-ref.

@StephenMolloy StephenMolloy merged commit a2b6674 into dotnet:main Aug 13, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2022
@dotnet dotnet unlocked this conversation Sep 14, 2022
@StephenMolloy
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/3055787467

@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2022
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.

System.Xml.Serialization.XmlSerializer.FromMappings throws NullReferenceException using a pre-generated serialization assembly

4 participants