[Mono-bugs] [Bug 710567] New: XmlDocument.Validate throws XmlSchemaValidationException when schema contains xsd:hexBinary attribute

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Aug 5 02:34:06 EDT 2011


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

https://bugzilla.novell.com/show_bug.cgi?id=710567#c0


           Summary: XmlDocument.Validate throws
                    XmlSchemaValidationException when schema contains
                    xsd:hexBinary attribute
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: x86
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: joe at mistachkin.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.19)
Gecko/20110707 Firefox/3.6.19 ( .NET CLR 3.5.30729; .NET4.0E)

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

namespace ConsoleApplication1
{
    class Program
    {
        private static string XML = @"<?xml version=""1.0""
encoding=""utf-8""?>
<blocks xmlns=""https://example.com/2009/schema"">
  <block publicKeyToken=""8bf43b4749e46a0b"" />
</blocks>
";

        private static string XSD = @"<?xml version=""1.0""
encoding=""utf-8""?>
<xsd:schema xmlns:extra=""https://example.com/2009/schema""
            xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
            elementFormDefault=""qualified""
            attributeFormDefault=""unqualified""
            targetNamespace=""https://example.com/2009/schema"">

  <xsd:complexType name=""block""
                   mixed=""true""
                   final=""#all"">

    <xsd:attribute name=""publicKeyToken""
                   type=""xsd:hexBinary""
                   use=""optional"" />

  </xsd:complexType>

  <xsd:complexType name=""blocks""
                   final=""#all"">
    <xsd:sequence>
      <xsd:element name=""block""
                   type=""extra:block""
                   minOccurs=""0""
                   maxOccurs=""unbounded"" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name=""blocks""
               type=""extra:blocks"" />
</xsd:schema>
";

        static void Main(string[] args)
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml(XML);
            document.Schemas.Add(XmlSchema.Read(
                new StringReader(XSD), null));

            document.Validate(null);
        }
    }
}


Reproducible: Always

Steps to Reproduce:
1. Compile and run the above C# code on .NET and Mono.
2. Observe that the results differ on .NET and Mono.

Actual Results:  
Unhandled Exception: System.Xml.Schema.XmlSchemaValidationException: XmlSchema
error: Failed to convert attribute value to type
http://www.w3.org/2001/XMLSchema:hexBinary ---> System.InvalidCastException:
Conversion from runtime type System.Byte[] to String is not supported
  at System.Xml.Schema.XmlAtomicValue.get_Value () [0x00000] in <filename
unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.AssessAttributeLocallyValid
(System.Xml.Schema.XmlSchemaAttribute attr, System.Xml.Schema.XmlSchemaInfo
info, System.Xml.Schema.XmlValueGetter getter) [0x00000] in <filename
unknown>:0
  --- End of inner exception stack trace ---
  at System.Xml.XmlReaderSettings.OnValidationError (System.Object o,
System.Xml.Schema.ValidationEventArgs e) [0x00000] in <filename unknown>:0
  at
Mono.Xml.Schema.XmlSchemaValidatingReader+<XmlSchemaValidatingReader>c__AnonStorey4.<>m__1
(System.Object o, System.Xml.Schema.ValidationEventArgs e) [0x00000] in
<filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError
(System.Xml.Schema.XmlSchemaValidationException exception, Boolean isWarning)
[0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError (System.String message,
System.Exception innerException, Boolean isWarning) [0x00000] in <filename
unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError (System.String message,
System.Exception innerException) [0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.AssessAttributeLocallyValid
(System.Xml.Schema.XmlSchemaAttribute attr, System.Xml.Schema.XmlSchemaInfo
info, System.Xml.Schema.XmlValueGetter getter) [0x00000] in <filename
unknown>:0
  at
System.Xml.Schema.XmlSchemaValidator.AssessAttributeElementLocallyValidType
(System.String localName, System.String ns, System.Xml.Schema.XmlValueGetter
getter, System.Xml.Schema.XmlSchemaInfo info) [0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute (System.String
localName, System.String ns, System.Xml.Schema.XmlValueGetter attributeValue,
System.Xml.Schema.XmlSchemaInfo info) [0x00000] in <filename unknown>:0
  at Mono.Xml.Schema.XmlSchemaValidatingReader.Read () [0x00000] in <filename
unknown>:0
  at System.Xml.XmlDocument.Validate (System.Xml.Schema.ValidationEventHandler
handler, System.Xml.XmlNode node, XmlSchemaValidationFlags flags) [0x00000] in
<filename unknown>:0
  at System.Xml.XmlDocument.Validate (System.Xml.Schema.ValidationEventHandler
handler) [0x00000] in <filename unknown>:0
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in
<filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION:
System.Xml.Schema.XmlSchemaValidationException: XmlSchema error: Failed to
convert attribute value to type http://www.w3.org/2001/XMLSchema:hexBinary --->
System.InvalidCastException: Conversion from runtime type System.Byte[] to
String is not supported
  at System.Xml.Schema.XmlAtomicValue.get_Value () [0x00000] in <filename
unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.AssessAttributeLocallyValid
(System.Xml.Schema.XmlSchemaAttribute attr, System.Xml.Schema.XmlSchemaInfo
info, System.Xml.Schema.XmlValueGetter getter) [0x00000] in <filename
unknown>:0
  --- End of inner exception stack trace ---
  at System.Xml.XmlReaderSettings.OnValidationError (System.Object o,
System.Xml.Schema.ValidationEventArgs e) [0x00000] in <filename unknown>:0
  at
Mono.Xml.Schema.XmlSchemaValidatingReader+<XmlSchemaValidatingReader>c__AnonStorey4.<>m__1
(System.Object o, System.Xml.Schema.ValidationEventArgs e) [0x00000] in
<filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError
(System.Xml.Schema.XmlSchemaValidationException exception, Boolean isWarning)
[0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError (System.String message,
System.Exception innerException, Boolean isWarning) [0x00000] in <filename
unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.HandleError (System.String message,
System.Exception innerException) [0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.AssessAttributeLocallyValid
(System.Xml.Schema.XmlSchemaAttribute attr, System.Xml.Schema.XmlSchemaInfo
info, System.Xml.Schema.XmlValueGetter getter) [0x00000] in <filename
unknown>:0
  at
System.Xml.Schema.XmlSchemaValidator.AssessAttributeElementLocallyValidType
(System.String localName, System.String ns, System.Xml.Schema.XmlValueGetter
getter, System.Xml.Schema.XmlSchemaInfo info) [0x00000] in <filename unknown>:0
  at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute (System.String
localName, System.String ns, System.Xml.Schema.XmlValueGetter attributeValue,
System.Xml.Schema.XmlSchemaInfo info) [0x00000] in <filename unknown>:0
  at Mono.Xml.Schema.XmlSchemaValidatingReader.Read () [0x00000] in <filename
unknown>:0
  at System.Xml.XmlDocument.Validate (System.Xml.Schema.ValidationEventHandler
handler, System.Xml.XmlNode node, XmlSchemaValidationFlags flags) [0x00000] in
<filename unknown>:0
  at System.Xml.XmlDocument.Validate (System.Xml.Schema.ValidationEventHandler
handler) [0x00000] in <filename unknown>:0
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in
<filename unknown>:0


Expected Results:  
No exception should be thrown (i.e. the XML document should validate as
correct).


This may be a regression in 2.10.3 as I believe this code used to work properly
on Mono.

-- 
Configure bugmail: https://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