[Mono-bugs] [Bug 622630] New: Custom XmlResolver doesn't always get called by RelaxNgPattern.Compile()

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jul 15 10:54:52 EDT 2010


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

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


           Summary: Custom XmlResolver doesn't always get called by
                    RelaxNgPattern.Compile()
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: All
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: guillaumeradde at hotmail.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.6)
Gecko/20100625 Firefox/3.6.6 GTB7.1

I have a relaxng schema embedded in a dll as a resource. The relaxng schema
includes other schemas, and those schemas include other schemas as well. All
the schemas are inside the dll. I use a custom XmlUrlLoader to load the
dependencies from inside my dll. However, it seems like the
RelaxngPAttern.Compile sometime calls my custom XmlUrlLoader, but also sometime
doesn't!

Here is the code I use:

----------------Code to load and compile the relaxngSchema

CMSD_RELAXNG_SCHEMA = "CMSD_V1.0.rng";
RelaxngPattern p = null;
XmlUrlResolver resolver = new EmbeddedResourceResolver(GetType());
using(XmlTextReader schema = new
XmlTextReader(Assembly.GetExecutingAssembly().Location,Assembly.GetExecutingAssembly().GetManifestResourceStream(this.GetType(),CMSD_RELAXNG_SCHEMA)))
            {
                Console.WriteLine("---- Reading Schema ----");
                p = RelaxngPattern.Read(schema,null,resolver);
                p.XmlResolver = resolver;
                Console.WriteLine("---- Compiling Schema ----");
                p.Compile();
            }
-------------My custom XmlUrlLoader

public class EmbeddedResourceResolver: XmlUrlResolver
        {
            private Type type;
            private Assembly assembly;
            public EmbeddedResourceResolver(Type t)
            {
                type = t;
                assembly = t.Assembly;
            }
            public override object GetEntity(Uri absoluteUri, string role, Type
ofObjectToReturn)
            {
                Console.WriteLine("  Getting Entity absoluteUri:{0}, role:{1},
type: {2}", absoluteUri,role,ofObjectToReturn.ToString());
                String fullPath = absoluteUri.AbsolutePath;
                String name = Path.GetFileName(fullPath);
                //return
assembly.GetManifestResourceStream(this.GetType(),name);
                return assembly.GetManifestResourceStream(this.GetType(),
absoluteUri.Segments[absoluteUri.Segments.Length - 1]);
            }
            public override Uri ResolveUri(Uri baseUri, string relativeUri)
            {
                Console.WriteLine("  Resolving Uri with baseUri: {0},
relativeUri: {1}", baseUri, relativeUri);
                if(baseUri == null)
                {
                    baseUri = new Uri(assembly.Location);
                }
                Uri res = base.ResolveUri(baseUri, relativeUri);
                Console.WriteLine("    ->Resolved to {0}", res);
                return res;
            }
        }
---------------------Here is the output on the console (I shortened the urls
for clarity)
---- Reading Schema ----
  Resolving Uri with baseUri: [...]CMSD.DLL, relativeUri: Packages.rng
    ->Resolved to [...]/Packages.rng
  Resolving Uri with baseUri: [...]/CMSD.DLL, relativeUri: Packages.rng
    ->Resolved to [...]/Packages.rng
---- Compiling Schema ----
  Resolving Uri with baseUri: [...]/CMSD.DLL, relativeUri: [...]/Packages.rng
    ->Resolved to [...]/Packages.rng
  Getting Entity absoluteUri:[...]/Packages.rng, role:, type: System.IO.Stream
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri: Support.rng
    ->Resolved to [...]/Support.rng
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri: Part.rng
    ->Resolved to [...]/Part.rng
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri:
ProductionPlanning.rng
    ->Resolved to [...]/ProductionPlanning.rng
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri: Resource.rng
    ->Resolved to [...]/Resource.rng
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri:
ProductionOperations.rng
    ->Resolved to [...]/ProductionOperations.rng
  Resolving Uri with baseUri: [...]/Packages.rng, relativeUri: Layout.rng
    ->Resolved to [...]/Layout.rng

Commons.Xml.Relaxng.RelaxngException: Could not include grammar
[...]/Support.rng: Could not find file '[...]\Support.rng'. [...]/Packages.rng
(21, 3)

at Commons.Xml.Relaxng.RelaxngElementBase.ReadExternalResource(RelaxngGrammar
grammar, Uri uri, String nsContext) 
at Commons.Xml.Relaxng.RelaxngInclude.Compile(RelaxngGrammar grammar) 
at Commons.Xml.Relaxng.RelaxngGrammar.Compile(RelaxngGrammar grammar) 
at Commons.Xml.Relaxng.RelaxngExternalRef.Compile(RelaxngGrammar grammar) 
at Commons.Xml.Relaxng.RelaxngBinaryContentPattern.makeBinary(RelaxngGrammar g) 
at Commons.Xml.Relaxng.RelaxngChoice.Compile(RelaxngGrammar grammar) 
at Commons.Xml.Relaxng.RelaxngGrammar.Compile(RelaxngGrammar grammar) 
at Commons.Xml.Relaxng.RelaxngPattern.Compile() 
at CMSD.RelaxNGCMSDValidator.Validate(String filePath) in
RelaxNGCMSDValidator.cs:line 38 
at CMSD.Support.DocumentDefinition.CMSDDocument.Validate(String filePath) in
CMSDDocument.cs:line 215 
at CMSD.Support.DocumentDefinition.CMSDDocument.ParseDocument(String url) in
CMSDDocument.cs:line 101 
at CMSD.Tests.CMSDDocumentTest.TestLoadThenWriteToFile() in
CMSDDocumentTest.cs:line 92 

System.IO.FileNotFoundException: Could not find file 'C:\Documents and
Settings\guiradde.MELAD\Local Settings\Application
Data\assembly\dl3\KG4HMO7L.BX3\RHMGORCO.076\b3cfb437\b39caaa8_2824cb01\Support.rng'.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) 
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize) 
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) 
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
ofObjectToReturn) 
at Commons.Xml.Relaxng.RelaxngElementBase.ReadExternalResource(RelaxngGrammar
grammar, Uri uri, String nsContext) 


---------------------Stacktrace of the exception I get:
Inner Exception:

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize)
   at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
ofObjectToReturn)
   at
Commons.Xml.Relaxng.RelaxngElementBase.ReadExternalResource(RelaxngGrammar
grammar, Uri uri, String nsContext)

Top level exception:

  at Commons.Xml.Relaxng.RelaxngElementBase.ReadExternalResource(RelaxngGrammar
grammar, Uri uri, String nsContext)
   at Commons.Xml.Relaxng.RelaxngInclude.Compile(RelaxngGrammar grammar)
   at Commons.Xml.Relaxng.RelaxngGrammar.Compile(RelaxngGrammar grammar)
   at Commons.Xml.Relaxng.RelaxngExternalRef.Compile(RelaxngGrammar grammar)
   at Commons.Xml.Relaxng.RelaxngBinaryContentPattern.makeBinary(RelaxngGrammar
g)
   at Commons.Xml.Relaxng.RelaxngChoice.Compile(RelaxngGrammar grammar)
   at Commons.Xml.Relaxng.RelaxngGrammar.Compile(RelaxngGrammar grammar)
   at Commons.Xml.Relaxng.RelaxngPattern.Compile()
   at CMSD.RelaxNGCMSDValidator.Validate(String filePath) 
-----------------------------
What surprises me is that in the inner exception, you can see that
System.Xml.XmlUrlResolver.GetEntity(...) is being called, even though I
provided my own xmlUrlResolver.

The relaxng schema used can be found here:
http://cmsdtools.hg.sourceforge.net/hgweb/cmsdtools/cmsdtools/file/c47ab352fc5c/resources/schema/rng_1.0/1.0

Reproducible: Always

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