Skip to content

Cannot serialize XML with nested classes - Microsoft.XmlSerializer.Generator 2.2.0  #36921

Description

@NUnitTester

The problems ocure while transforming a project from .NET Framework to .NET Core 3.1 with
Microsoft.XmlSerializer.Generator 2.2.0.
It seems to be a bug in the generator. There should be no reason to analyze types that are not serialzed.

The following example works fine with .NET Frameworks but fails in .NET Core.

    public class A
    {
        public enum Error
        { no = 0 }

        [XmlElement("value")] 
        public string V;
    }
    public class B
    {
        public enum Error
        { no = 0 }

        [XmlElement("value")] 
        public string V;
    }

Error Message:
There was an error reflecting type 'N.B.Error'.
Types 'N.B.Error' and 'N.A.Error' both use the XML type name, 'Error', from namespace ''. Use XML attributes to specify a unique XML name and/or namespace for the type.

It seems not to be neccessary but it does not help anything:

    public class A
    {
        [XmlType("Error", Namespace = "A")]
        public enum Error
        { no = 0 }

        [XmlElement("value")] 
        public string V;
    }
    public class B
    {
        [XmlType("Error", Namespace = "B")]
        public enum Error
        { no = 0 }

        [XmlElement("value")] 
        public string V;
    }

Error Message:
The top XML element 'Error' from namespace '' references distinct types N.A.Error and N.B.Error. Use XML attributes to specify another XML name or namespace for the element or types.

There is no way out ... I found nothing.
Please solve the problem urgent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions