[Mono-bugs] [Bug 472634] New: XmlWriter.WriteAttributeString() behaves differently than Microsoft implementation with null namespace parameter.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Feb 4 16:29:28 EST 2009


           Summary: XmlWriter.WriteAttributeString() behaves differently
                    than Microsoft implementation with null namespace
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.2.x
          Platform: Macintosh
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: dmitchell at logos.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us)
AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1

In Microsoft's implementation of .NET, XmlWriter.WriteAttributeString() is more
liberal about what it accepts than Mono's implementation. For example this


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,



Runs without trouble under the Microsoft implementation, producing this output:


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


However, running the same code under Mono results in 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


The reason appears to be that Microsoft allows specifying a namespace prefix
without the actual namespace if the namespace has already been defined
elsewhere. Mono seems to require the namespace except in cases such as the
"xmlns" prefix.

This is a significant issue in my organization's codebase because there are
many times that we may know the prefix without actually knowing the namespace

Reproducible: Always

Steps to Reproduce:
1. Compile the code listed above. Make sure that System.Xml is referenced.
2. Run
Actual Results:  
Code crashes under Mono

Expected Results:  
The following should be output:

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

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list