Bug 26383 - DataContractSerializer Ctor Throws ArgumentNullException When Passed New DataContractSerializerSettings
Summary: DataContractSerializer Ctor Throws ArgumentNullException When Passed New Data...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Runtime.Serialization ()
Version: 3.12.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-01-24 13:09 UTC by Anthony Sneed
Modified: 2018-03-13 12:20 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Unit Test for DataContractSerialzer ctor that accepts settings. (501 bytes, application/octet-stream)
2015-01-24 13:09 UTC, Anthony Sneed

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Anthony Sneed 2015-01-24 13:09:56 UTC
Created attachment 9484 [details]
Unit Test for DataContractSerialzer ctor that accepts settings.

The constructor for the DataContractSerializer throws an ArgumentNullException for rootName when passed a new DataContractSerializerSettings class.  The reason is that the ctor which accepts DataContractSerializerSettings calls another ctor which checks if rootName or rootNamespace are null, which they are by default on the settings class.  See https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs.

This behavior is different than .NET 4.5 on Windows, which does not perform the null check on these parameters.  See https://github.com/Microsoft/referencesource/blob/master/System.Runtime.Serialization/System/Runtime/Serialization/DataContractSerializer.cs.

The attached unit test passes on Windows but fails on OSX.

This bug is affecting the Xml formatters for ASP.NET 5, which use DataContractSerialzer with the settings class, as described in this pull request: https://github.com/aspnet/Mvc/pull/1871.

Tony Sneed
Comment 1 Marek Safar 2018-03-13 12:20:47 UTC
It works as expected with recent Mono versions