Bug 19426 - Microsoft Xml Document Transform SetAttributes fails with ArgumentNullException
Summary: Microsoft Xml Document Transform SetAttributes fails with ArgumentNullException
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-04-30 13:43 UTC by Matt Ward
Modified: 2015-05-11 09:51 UTC (History)
3 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 Matt Ward 2014-04-30 13:43:40 UTC
Created attachment 6683 [details]
Unit test for XDT SetAttributes

Using Microsoft's Xml Document Transform library with a transform that updates attributes fails when running on Mono with an Argument cannot be null exception.

Tested with Mono 3.4.0 - MonoFramework-MDK-
Microsoft.Web.Xdt library v1.0.0.0 from NuGet.

Test class is attached. Full project code is available on github: https://github.com/mrward/xdt-mono-tests


Microsoft.Web.XmlTransform.XmlNodeException: Argument cannot be null.
Parameter name: key ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: key
  at System.Xml.NameTable.Add (System.String key) [0x00006] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.XML/System.Xml/NameTable.cs:92 
  at System.Xml.XmlAttribute.set_Prefix (System.String value) [0x0004b] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.XML/System.Xml/XmlAttribute.cs:197 
  at Microsoft.Web.XmlTransform.XmlElementContext.ScrubTransformAttributesAndNamespaces (System.Xml.XmlNode node) [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.XmlElementContext.CreateCloneInTargetDocument (System.Xml.XmlNode sourceNode) [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.XmlElementContext.get_TransformNode () [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.Transform.get_TransformNode () [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes () [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.Transform.Execute (Microsoft.Web.XmlTransform.XmlElementContext context, System.String argumentString) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogErrorFromException (System.Exception ex) [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.Transform.Execute (Microsoft.Web.XmlTransform.XmlElementContext context, System.String argumentString) [0x00000] in <filename unknown>:0 
  at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement (Microsoft.Web.XmlTransform.XmlElementContext context) [0x00000] in <filename unknown>:0 

Looking at the Mono source code the underlying problem seems to be that with Microsoft's .NET Framework you can set the XmlAttribute.Prefix to null but not with Mono. The test below will fail on Mono but works with Microsoft's .NET Framework.

	public class XmlAttributeTests
		public void SetPrefixToNull ()
			var doc = new XmlDocument ();
			doc.LoadXml ("<root attr='' />");
			XmlAttribute attribute = doc.DocumentElement.Attributes [0];

			Assert.DoesNotThrow (() => attribute.Prefix = null);

			Assert.AreEqual (String.Empty, attribute.Prefix);
Comment 1 Atsushi Eno 2015-03-17 16:21:24 UTC
This should be now compatible with .NET as XmlDocument is based on referencesource.
Comment 2 Matt Ward 2015-05-11 09:51:28 UTC
Mono 4.0 and Mono 4.0.1 alpha (f802480 May 6) seem to be using the old XML code and not the new version based on the reference source. So I guess this will be fixed in a later Mono version.