Bug 27424 - XmlSchemaValidationException "Not allowed character content was found" thrown when abstract complex types has no elements
Summary: XmlSchemaValidationException "Not allowed character content was found" thrown...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-02-25 13:37 UTC by Esteban Troscé
Modified: 2015-03-17 17:05 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Schema defining an abstract complex type with no elements (839 bytes, application/octet-stream)
2015-02-25 13:37 UTC, Esteban Troscé
Details
Project that reproduces the bug (2.54 KB, application/x-gzip)
2015-02-25 13:48 UTC, Esteban Troscé
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Esteban Troscé 2015-02-25 13:37:38 UTC
Created attachment 10030 [details]
Schema defining an abstract complex type with no elements

Take a look at the attached xsd. It defines an abstract complex type without elements. When validating the following xml against the attached xsd file, it fails with "Not allowed character content was found". Looks like it complains about a 0xA char at the end of the child line:

<?xml version="1.0" encoding="UTF-8" ?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <parent xsi:type="DerivedA">
    <childA/>
  </parent>
</root>

Two workarounds:

1) Define a dummy element for the abstract complex type: 
<xs:choice maxOccurs="unbounded">
  <xs:element minOccurs="0" name="dummy"/>
</xs:choice>

2) Remove the 0xA char from the end of the child elements:
<parent xsi:type="DerivedA"><childA/></parent>

The following code reproduces the problem:

void ReadXml(string xmlPath, string schemaPath)
{
  XmlSchemaSet schemas = new XmlSchemaSet();
  schemas.Add(null, schemaPath);

  XmlReaderSettings settings = new XmlReaderSettings
  {
    Schemas = schemas,
    ValidationType = ValidationType.Schema
  };

  using (XmlReader reader = XmlReader.Create(xmlPath, settings))
  {
    while (reader.Read());
  }
}
Comment 1 Esteban Troscé 2015-02-25 13:48:07 UTC
Created attachment 10031 [details]
Project that reproduces the bug
Comment 2 Atsushi Eno 2015-03-17 16:48:27 UTC
Our System.Xml.Schema is referencesource based and it validates as expected.
Comment 3 Esteban Troscé 2015-03-17 17:05:50 UTC
Sorry, do you mean that validation is expected to fail if there is a 0xA character between child nodes just because the type derives from an abstract one with no members?