镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions