[Mono-bugs] [Bug 582428] New: ResXResourceWriter does not recreate resource file, instead writes in file and leaves inconsistent XML. Also forgets to write resource comments.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Feb 23 16:07:33 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=582428

http://bugzilla.novell.com/show_bug.cgi?id=582428#c0


           Summary: ResXResourceWriter does not recreate resource file,
                    instead writes in file and leaves inconsistent XML.
                    Also forgets to write resource comments.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: kuritsu at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=344229)
 --> (http://bugzilla.novell.com/attachment.cgi?id=344229)
Test Case which shows the bug.

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; es-MX; rv:1.9.1.5)
Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5

The class ResXResourceWriter does not recreate a resx file when using the
ResXResourceWriter(string fileName) constructor overload. Instead, it opens for
writing a file (creates it if the file doesn't exist), writes the resources
without comments and leaves the resx in an inconsistent state of XML schema.

Reproducible: Always

Steps to Reproduce:
1. Create a C# console application using MonoDevelop.
2. Add System.Windows.Forms as reference.
3. Add System.Resources and System.IO in the usings section.
4. In the Main method of the main class of the project, copy and paste the
following code:

    ResXResourceWriter writer = new ResXResourceWriter("Resources.resx");
    ResXDataNode node = new ResXDataNode("key1", "value1");
    node.Comment = "comment1";
    writer.AddResource(node);
    node = new ResXDataNode("key2", "value2");
    node.Comment = "comment2";
    writer.AddResource(node);
    writer.Close();
    File.Copy("Resources.resx", "Resources2.resx");
    writer = new ResXResourceWriter("Resources2.resx");
    node = new ResXDataNode("k1", "v1");
    node.Comment = "c1";
    writer.AddResource(node);
    node = new ResXDataNode("k2", "v2");
    node.Comment = "c2";
    writer.AddResource(node);
    writer.Close();
5. Check the two resulting files, Resources.resx and Resources2.resx.
Actual Results:  
The Resources2.resx file is the following:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0"
msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1"
/>
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"
/>
              <xsd:attribute name="mimetype" type="xsd:string"
msdata:Ordinal="4" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
<resheader
name="resmimetype"><value>text/microsoft-resx</value></resheader><resheader
name="version"><value>1.3</value></resheader><resheader
name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</value></resheader><resheader
name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</value></resheader><data
name="k1"><value>v1</value></data>
  <data name="k2"><value>v2</value></data>
  </root>a>
  </root>me="key3"><value>value3</value></data>
  </root>

Check how the root document element ends and then the file continues with the
original characters from Resources.resx, leaving an inconsistent XML. Note
there's no comment tags also.

Expected Results:  
The resulting Resources2.resx should have being like this:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0"
msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1"
/>
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"
/>
              <xsd:attribute name="mimetype" type="xsd:string"
msdata:Ordinal="4" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
<resheader
name="resmimetype"><value>text/microsoft-resx</value></resheader><resheader
name="version"><value>1.3</value></resheader>
<resheader name="reader"><value>System.Resources.ResXResourceReader,
System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</value></resheader><resheader
name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="k1"><value>v1</value><comment>c1</comment></data>
  <data name="k2"><value>v2</value><comment>c2</comment></data>
  </root>

Check that the document ends normally and the comment tags are included.

This bug causes also to fail ResXResourceReader from reading the inconsistent
file.

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


More information about the mono-bugs mailing list