Bug 7830 - When deserializing a class with values initialized to null, InvalidOperationException thrown on Array.Copy
Summary: When deserializing a class with values initialized to null, InvalidOperationE...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
Depends on:
Reported: 2012-10-14 12:08 UTC by Rhys
Modified: 2014-12-09 06:06 UTC (History)
2 users (show)

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

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 Rhys 2012-10-14 12:08:02 UTC
Description of Problem:
Deserializing an object from a class that has values that default to null, an InvalidOperationException is thrown. The root InnerException reveals that it happens on an Array.Copy operation. The error reported on the main exception received is "Cannot Reflect Type X".

Steps to reproduce the problem:
1. Create a class with public variables initialised to null
2. Add [XmlRoot("X")] to the class declaration
3. Deserialize an XML file conforming to this class

Actual Results:
InvalidOperationException thrown

Expected Results:
The Class is deserialized successfully as is the case on Windows via Microsoft's .NET runtime

How often does this happen? 
Every time
Comment 1 marcos.henrich 2014-08-26 08:07:37 UTC
Hi Rhys.

Thank you for the bug report. 

I was not able to reproduce the issue. Below is my attempt.

Please provide us the class and the text you are trying to deserialize.

using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace XmlDebugApp
	public class Program

		public class ClassWithNullField
			public string Text = null;
			public object Object = null;
		static void Main(string[] args)
		    var ser = new XmlSerializer (typeof (ClassWithNullField));
			var obj = new ClassWithNullField {};
			obj.Text = "sdfsf";
			using (var w = new StringWriter ()) {
				ser.Serialize (w, obj);
				using (var r = new StringReader ( w.ToString ())) {
					var desObj = ser.Deserialize (r);
Comment 2 marcos.henrich 2014-12-09 06:06:36 UTC
Unable to reproduce the issue from description.