drewnoakes / xmp-core-dotnet

.NET library for working with the Extensible Metadata Platform (XMP)
60 stars 22 forks source link

System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name. #16

Closed ChristopherLea closed 8 years ago

ChristopherLea commented 8 years ago

Hi there,

System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.

I'm trying to use XMPCore.net inside a PCL, and get the above error when using XmpCore.Portable.

I've successfully integrated it into a normal C# library and have several unit tests with accompanying test documents containing XMP. They work just fine with the 'regular' XmpCore.

However when reusing the same code, unit tests and sample documents I get an XML Error with the Portable XMPCore when trying to parse the XMP (from string or buffer). The XMP verifies just fine on w3c and indeed is successfully parsed using non portable XMPCore.

I've tried registering the namespace before parsing with no luck, any ideas?

Thanks for any help, Chris

ChristopherLea commented 8 years ago

Call stack is below.

    Read [FAIL] : System.Xml.XmlException : The ':' character, hexadecimal value 0x3A, cannot be included in a name.
10-27 14:08:57.525 I/mono-stdout( 3838):    Read [FAIL] : System.Xml.XmlException : The ':' character, hexadecimal value 0x3A, cannot be included in a name.
          at System.Xml.XmlConvert.VerifyNCName (System.String name, System.Xml.ExceptionType exceptionType) [0x00045] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml/System/Xml/XmlConvert.cs:395 
10-27 14:08:57.527 I/mono-stdout( 3838):          at System.Xml.XmlConvert.VerifyNCName (System.String name, System.Xml.ExceptionType exceptionType) [0x00045] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml/System/Xml/XmlConvert.cs:395 
          at System.Xml.XmlConvert.VerifyNCName (System.String name) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml/System/Xml/XmlConvert.cs:380 
          at System.Xml.Linq.XName..ctor (System.Xml.Linq.XNamespace ns, System.String localName) [0x0000d] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:48 
10-27 14:08:57.528 I/mono-stdout( 3838):          at System.Xml.XmlConvert.VerifyNCName (System.String name) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml/System/Xml/XmlConvert.cs:380 
          at System.Xml.Linq.XNamespace.GetName (System.String localName, System.Int32 index, System.Int32 count) [0x00017] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:427 
10-27 14:08:57.528 I/mono-stdout( 3838):          at System.Xml.Linq.XName..ctor (System.Xml.Linq.XNamespace ns, System.String localName) [0x0000d] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:48 
10-27 14:08:57.529 I/mono-stdout( 3838):          at System.Xml.Linq.XNamespace.GetName (System.String localName, System.Int32 index, System.Int32 count) [0x00017] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:427 
          at System.Xml.Linq.XNamespace.GetName (System.String localName) [0x00011] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:278 
10-27 14:08:57.531 I/mono-stdout( 3838):          at System.Xml.Linq.XNamespace.GetName (System.String localName) [0x00011] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:278 
          at System.Xml.Linq.XName.Get (System.String expandedName) [0x0009a] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:100 
10-27 14:08:57.532 I/mono-stdout( 3838):          at System.Xml.Linq.XName.Get (System.String expandedName) [0x0009a] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:100 
          at System.Xml.Linq.XName.op_Implicit (System.String expandedName) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:121 
10-27 14:08:57.532 I/mono-stdout( 3838):          at System.Xml.Linq.XName.op_Implicit (System.String expandedName) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:121 
10-27 14:08:57.535 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_ResourcePropertyElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x00009] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_ResourcePropertyElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x00009] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_PropertyElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x00260] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_PropertyElementList (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlParent, System.Boolean isTopLevel) [0x0003f] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_NodeElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x0003d] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_NodeElementList (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement rdfRdfNode) [0x0001d] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Rdf_RDF (XmpCore.Impl.XmpMeta xmp, System.Xml.Linq.XElement rdfRdfNode) [0x00015] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.540 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_PropertyElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x00260] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.540 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_PropertyElementList (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlParent, System.Boolean isTopLevel) [0x0003f] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.540 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_NodeElement (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement xmlNode, System.Boolean isTopLevel) [0x0003d] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.540 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_NodeElementList (XmpCore.Impl.XmpMeta xmp, XmpCore.Impl.XmpNode xmpParent, System.Xml.Linq.XElement rdfRdfNode) [0x0001d] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.541 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Rdf_RDF (XmpCore.Impl.XmpMeta xmp, System.Xml.Linq.XElement rdfRdfNode) [0x00015] in <509f73465b0f4b0e867369cb2d53af48>:0 
10-27 14:08:57.541 I/mono-stdout( 3838):          at XmpCore.Impl.ParseRdf.Parse (System.Xml.Linq.XElement xmlRoot) [0x00005] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.ParseRdf.Parse (System.Xml.Linq.XElement xmlRoot) [0x00005] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.XmpMetaParser.ParseXmlDoc (System.Xml.Linq.XDocument document, XmpCore.Options.ParseOptions options) [0x0002b] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.Impl.XmpMetaParser.Parse (System.String xmlStr, XmpCore.Options.ParseOptions options) [0x00019] in <509f73465b0f4b0e867369cb2d53af48>:0 
          at XmpCore.XmpMetaFactory.ParseFromString (System.String packet, XmpCore.Options.ParseOptions options) [0x00000] in <509f73465b0f4b0e867369cb2d53af48>:0
ChristopherLea commented 8 years ago

Hi there,

Decided to build from source rather than NuGet to investigate further, and I get the exact same error when running XmpCore.Tests?

// ============================================================================= // Test simple constructors and parsing, setting the instance ID // =============================================================================

Empty XMP object: ROOT NODE

XMP object with name (Name: 'New object name'): ROOT NODE (New object name)

Caught exception 'The ':' character, hexadecimal value 0x3A, cannot be included in a name.'

Any help would be greatly appreciated!

drewnoakes commented 8 years ago

I think some recent refactoring might have broken this. Potentially an implicit cast from string to XNamespace or XName caused an overload resolution change. Investigating.

drewnoakes commented 8 years ago

Are you running the tests under Mono? The tests are passing on my machine (not Mono).

drewnoakes commented 8 years ago

Could you try running the tests on commit f92a82163f5664ca025831827f3c8f9b3c22f268 please? That commit is before some recent refactoring.

If they pass, it'd be amazing if you could use git bisect to find the offending commit.

ChristopherLea commented 8 years ago

Hi Drew,

First thanks for getting back to me :)!.

I'm not running the tests under Mono, although I do have Xamarin installed (my intention is to use XmpCore inside a current Xamarin project).

I've narrowed it down to the following code: if (isTopLevel && xmlNode.Name == "iX:changes") { // Strip old "punchcard" chaff which has on the prefix "iX:". return; }

If this check is removed, all is well.

I will try with an older commit and get back to you.

Thanks

drewnoakes commented 8 years ago

That line of code was changed recently. The code was converted from Java, where == is a reference check for strings. I got tired of reading str1.Equals(str2) everywhere in the C# code, so used a structural search and replace (via ReSharper) to update the code in 6fcf0546961417979596f4407d80c418e7790b6b. I suspect that broke this line of code, and potentially others as well.

drewnoakes commented 8 years ago

The diff there was:

         /// <exception cref="XmpException">thrown on parsing errors</exception>
          private static void Rdf_ResourcePropertyElement(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
          {
 -            if (isTopLevel && "iX:changes".Equals(xmlNode.Name))
 +            if (isTopLevel && xmlNode.Name == "iX:changes")
              {
                  // Strip old "punchcard" chaff which has on the prefix "iX:".
                  return;
              }

If you change it back to "iX:changes".Equals(xmlNode.Name), does it pass?

I will have to think whether it makes sense to revert that commit, or go through and review each change for problems. I doubt that is the only case.

ChristopherLea commented 8 years ago

Just tried with f92a821 and works fine.

Sorry the probably stupid questions but I'm completely new to this NuGet etc. situation (I'm used to Embedded C++ and Linux so a bit out of my depth!).

What would be the best way to include this older revision as a portable dll in my Xamarin project? Is it possible to cross reference the git hash with NuGet versions and use an older download?

drewnoakes commented 8 years ago

This bug will not be present in version 1.2.2 of the NuGet package. You should be able to update your project to reference the earlier version and be good to go.

ChristopherLea commented 8 years ago

Thanks Drew, rolled back to 1.2.2 and my Android Unit Test App is now passing!

Brilliant, thank you so much for your help.

drewnoakes commented 8 years ago

Great. I'm going to re-open this to track the bug in 1.2.3. I'll get a fix out soon and let you know.

drewnoakes commented 8 years ago

@ChristopherLea I've fixed the above issue, and also made the library target netstandard1.0 instead of the older PCL profile. It's now built using project.json instead of multiple .csproj files.

Would you be able to test the 2.0.0-rc1 package on NuGet please?

https://www.nuget.org/packages/XmpCore/2.0.0-rc1

drewnoakes commented 8 years ago

2.0.0-rc2 exists now, with support for net35, as well as netstandard10. Both include fixes for this issue.

drewnoakes commented 8 years ago

I've also deleted 1.2.3 from NuGet.