Skip to content

Cannot serialize XML with nested classes (2) - Microsoft.XmlSerializer.Generator 2.2.0 #36925

@NUnitTester

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.

    [Serializable]
    [XmlRoot("Info", Namespace = "N1")]
    public class Info1
    {
        [Flags]
        public enum Flag : uint
        {
            F1 = 1,
            F2 = 2,
            All = 3,
        }

        [XmlAttribute("flags")] 
        public Flag F { get; set; }
    }

    [Serializable]
    [XmlRoot("Info", Namespace = "N2")]
    public class Info2
    {
        [Flags]
        public enum Flag : uint
        {
            F1 = 1,
            F2 = 2,
            All = 3,
        }

        [XmlAttribute("flags")] 
        public Flag F { get; set; }
    }

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

Should not they have the same namespace as outdie the class including it? N1 or N2?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions