[Mono-dev] XmlWriter.WriteAttributeString incompatible with MS implementation

David Mitchell dmitchell at logos.com
Wed Feb 4 11:58:33 EST 2009

Currently, when I go to http://bugzilla.novell.com, I get a 504 error. When
that clears up, I'll be happy to file an official bug, but until then,
here's a snippet of code:

using System;
using System.IO;
using System.Xml;

namespace FunWithXmlAttributes
	class MainClass
		public static void Main(string[] args)
			using (StringWriter writerString = new StringWriter())
				using (XmlWriter writerXml = XmlWriter.Create(writerString, new
XmlWriterSettings { Indent = false,
					CloseOutput = false, OmitXmlDeclaration = true }))
					writerXml.WriteAttributeString("xmlns", "abc", null,
					writerXml.WriteAttributeString("abc", "def", null, "value");


On Windows (with the MS implementation), the output is this:

<root xmlns:abc="uri:abcnamespace" abc:def="value" />

While in OSX, I get this exception:

Unhandled Exception: System.ArgumentException: Namespace URI must not be
null when prefix is not an empty string.
  at System.Xml.XmlTextWriter.WriteStartAttribute (System.String prefix,
System.String localName, System.String namespaceUri) [0x00272] in
  at System.Xml.XmlWriter.WriteAttributeString (System.String prefix,
System.String localName, System.String ns, System.String value) [0x00000] in
  at FunWithXmlAttributes.MainClass.Main (System.String[] args) [0x0004a] in


Atsushi Eno wrote:
> Hello,
> If you file a bug on our bugzilla, I might "fix" the implementation 
> difference, depending on the repro, without the patch you have.
> http://bugzilla.novell.com
> Atsushi Eno
> David Mitchell wrote:
>> I'm currently trying to port the back-end of a very large project over to
>> OSX
>> from Windows, and I've encountered a rather vexing incompatibility
>> between
>> Mono and Microsoft's implementation of .NET.
>> The documentation for XmlWriter.WriteAttributeString(string prefix,
>> string
>> localName, string ns, string value) seems to indicate that if a prefix is
>> provided and a namespace is not, that the method may throw an
>> ArgumentException, and this is what Mono does. However, Microsoft's
>> implementation allows this scenario if the given prefix has already been
>> associated with a namespace.
>> This wouldn't be a terribly big deal, except that the XmlWriter provides
>> no
>> way to determine the namespace associated with a prefix, and we have many
>> cases in which we only have a prefix to work with. Is there any chance of
>> getting this behavior modified to conform to Microsoft's implementation?
>> I'd
>> submit a patch myself, but as I was investigating this issue with a
>> coworker, he opened up the relevant classes in Reflector, so I'm
>> tainted...
>> Thanks,
>> --Dave
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

View this message in context: http://www.nabble.com/XmlWriter.WriteAttributeString-incompatible-with-MS-implementation-tp21815568p21834689.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list