Bug 17012 - Exception "Could not resolve schema location URI" is thrown for valid files
Summary: Exception "Could not resolve schema location URI" is thrown for valid files
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-01 12:39 UTC by Thanassis Tsiodras
Modified: 2015-03-17 17:17 UTC (History)
2 users (show)

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


Attachments
Complete reproducible test case with F# source code and data (4.20 KB, application/x-bzip)
2014-01-01 12:39 UTC, Thanassis Tsiodras
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 Thanassis Tsiodras 2014-01-01 12:39:15 UTC
Created attachment 5743 [details]
Complete reproducible test case with F# source code and data

After loading two .xml files that are validated via corresponding .xsd schemas, I am getting an error, even though both  .xml files validate fine outside Mono (e.g. when the program is run under Windows - and thus uses the .NET version of the System.Xml.dll library - or validation is done with different tools, e.g. "SAXCount -n -s -f CustomWebServices.xml")

I managed to reproduce the error with a small, standalone F# program, whose source code I attach along with the data that trigger the error.

To reproduce, untar the attached tarball, and run ./bug.sh. You will see the following error message, after 'fsharpc' finishes the compilation and the generated executable is run:

    Processing /home/ttsiod/work/bug/project.xml
    Processing /home/ttsiod/work/bug/CustomWebServices.xml
    Warning '/home/ttsiod/work/bug/CustomWebServices.xml':line 2, XmlSchema error: Could not resolve schema location URI: CustomWSSchema.xsd XML URI: file:///home/ttsiod/work/bug/CustomWebServices.xml . Line 2, Position 2.
    Warning '/home/ttsiod/work/bug/CustomWebServices.xml':line 2, XmlSchema error: Could not resolve schema location URI: CustomWSSchema.xsd XML URI: file:///home/ttsiod/work/bug/CustomWebServices.xml . Line 2, Position 2.
    Error in file: /home/ttsiod/work/bug/CustomWebServices.xml

    Unhandled Exception:
    System.Exception: One or more errors detected in the xml parsing
      at Program.loadXmlFile (System.String xmlFileName) [0x00000] in <filename unknown>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: One or more errors detected in the xml parsing
      at Program.loadXmlFile (System.String xmlFileName) [0x00000] in <filename unknown>:0 

Both .xml files are fine, xsd-wise:

    $ SAXCount -n -s -f project.xml
    project.xml: 21 ms (64 elems, 75 attrs, 424 spaces, 231 chars)

    $ SAXCount -n -s -f CustomWebServices.xml
    CustomWebServices.xml: 9 ms (5 elems, 13 attrs, 51 spaces, 148 chars)

... and the same code runs fine when compiled under Windows and executed with the .NET version of System.Xml.dll.
It appears that loading the second .xml file - which is done via the same function as for the first .xml file - somehow triggers a bug in Mono's version of the System.Xml.dll library...

I tested under both Arch Linux (Mono 3.2.3) and Debian (Mono 2.10.8.1) - the problem manifests in both.
Comment 1 Thanassis Tsiodras 2014-01-02 05:53:14 UTC
I narrowed it down even further - the error was caused by a typo in the .xsd, which is apparently somehow breaking the .xsd loader: I had...

    <xsd:element ref = "Returns " minOccurs = "1" maxOccurs = "1"/>

instead of

    <xsd:element ref = "Returns" minOccurs = "1" maxOccurs = "1"/>

(notice the space at the end of the 'ref' attribute.
Apparently, both the .NET implementation and XERCES (the validating engine behind SAXCount) are trimming the attribute strings...

I am not versed enough in the standards to know whether the Mono implementation is right to break (and the others are wrong to silently accept this)... But I am pretty sure that the error reported should be something better than "Could not resolve schema location URI" at the referencing .xml file...
Comment 2 Atsushi Eno 2015-03-17 17:17:19 UTC
F# is somehow causing crashes on Ubuntu now and I cannot verify the repro but since System.Xml.Schema has switched to referencesource the behavior should be the same as .NET now.