[Mono-bugs] [Bug 474091] New: XmlWriter.WriteElementString()/WriteStartElement() behave differently than Microsoft implementation with null namespace parameter.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Feb 9 16:39:09 EST 2009


User dmitchell at logos.com added comment

           Summary: XmlWriter.WriteElementString()/WriteStartElement()
                    behave 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
                CC: dmitchell at logos.com
        Depends on: 472634
          Found By: ---

+++ This bug was initially created as a clone of Bug #472634 +++

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.WriteElementString("abc", "def", null, "value");



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


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


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.WriteStartElement (System.String prefix,
System.String localName, System.String namespaceUri) [0x0030e] in
  at System.Xml.XmlWriter.WriteElementString (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</abc:def></root>

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