[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


https://bugzilla.novell.com/show_bug.cgi?id=472634


           Summary: XmlWriter.WriteAttributeString() behaves differently
                    than Microsoft implementation with null namespace
                    parameter.
    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
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.WriteStartElement("root");
                    writerXml.WriteAttributeString("xmlns", "abc", null,
"uri:abcnamespace");
                    writerXml.WriteAttributeString("abc", "def", null,
"value");
                    writerXml.WriteEndElement();
                }

                Console.WriteLine(writerString.ToString());
            }
        }
    }
}

---

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
/private/tmp/monobuild/build/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:886 
 at System.Xml.XmlWriter.WriteAttributeString (System.String prefix,
System.String localName, System.String ns, System.String value) [0x00000] in
/private/tmp/monobuild/build/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlWriter.cs:243 
 at FunWithXmlAttributes.MainClass.Main (System.String[] args) [0x0004a] in
/Users/dmitchell/Projects/FunWithXmlAttributes/FunWithXmlAttributes/Main.cs:18

---

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
itself.

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