aas-core-works / aas-core3.0-csharp

Manipulate, verify and de/serialize asset administration shells in C#.
Other
7 stars 1 forks source link

XML Prolog in aas-spec causes error on deserialization of AASX package #24

Closed CHRiSLY78 closed 1 year ago

CHRiSLY78 commented 1 year ago

Trying to deserialize an AASX package containing an XML aas-spec with leading XML prolog I get the following error message:

Expected an XML element representing an instance of class Environment, but got a node of type XmlDeclaration with value version="1.0" encoding="UTF-8" at: 

(nothing after at:)

Not working example:

<?xml version="1.0" encoding="UTF-8"?>
<environment xmlns="https://admin-shell.io/aas/3/0" xmlns:IEC="http://www.admin-shell.io/IEC61360/2/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:abac="http://www.admin-shell.io/aas/abac/2/0" xsi:schemaLocation="https://admin-shell.io/aas/3/0 AAS.xsd http://www.admin-shell.io/IEC61360/2/0 IEC61360.xsd" xmlns:aas="https://admin-shell.io/aas/3/0">
    <assetAdministrationShells>
        <assetAdministrationShell>
[...]

Removing the XML prolog from aas-spec file within the package resolves the error. Working example:

<environment xmlns="https://admin-shell.io/aas/3/0" xmlns:IEC="http://www.admin-shell.io/IEC61360/2/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:abac="http://www.admin-shell.io/aas/abac/2/0" xsi:schemaLocation="https://admin-shell.io/aas/3/0 AAS.xsd http://www.admin-shell.io/IEC61360/2/0 IEC61360.xsd" xmlns:aas="https://admin-shell.io/aas/3/0">
    <assetAdministrationShells>
        <assetAdministrationShell>
[...]

I was not able to find any restriction to XML prologs in part 5 of the specification or at https://github.com/admin-shell-io/aas-specs/tree/master/schemas/xml. And it would surprise me, if there were any in this case to be honest.

Have I overseen something or might this be wrong behavior on aas-core side?

mristin commented 1 year ago

@CHRiSLY78 thanks for posting the issue! Please have a look at the note regarding MoveToContent in the documentation:

https://aas-core-works.github.io/aas-core3.0-csharp/getting_started/xmlize.html#de-serialize

Please re-open if it does not solve the issue.

mristin commented 1 year ago

I'm leaving this open as the error message needs to improve.

mristin commented 1 year ago

@CHRiSLY78 a new patch version should be on nuget soon: https://github.com/aas-core-works/aas-core3.0-csharp/releases/tag/v1.0.0-rc5