LinqToXsdCore icon indicating copy to clipboard operation
LinqToXsdCore copied to clipboard

Generated code doesn't compile if an element is named Content

Open Guymestef opened this issue 3 years ago • 3 comments

Hello,

I've got a naming collision when an element is named Content in the xsd file.

When I generate the model for the following xsd files: https://www.rixml.org/images/docs/schemas/RIXML-2_5.xsd https://www.rixml.org/images/docs/schemas/RIXML-Common-2_5.xsd https://www.rixml.org/images/docs/schemas/RIXML-datatypes-2_5.xsd

With this config file:

<?xml version="1.0" encoding="utf-8"?>
<Configuration xmlns="http://www.microsoft.com/xml/schema/linq">
 <CodeGeneration>
   <SplitCodeFiles By="Namespace" />
 </CodeGeneration>
 <Namespaces>
   <Namespace DefaultVisibility="public" Schema="http://www.rixml.org/2017/9/RIXML" Clr="Pretrade.Api.PublicationExport.Services.Features.Attachment.Models.Rixml" />
   <Namespace DefaultVisibility="public" Schema="http://www.rixml.org/2017/9/RIXML-datatypes" Clr="Pretrade.Api.PublicationExport.Services.Features.Attachment.Models.Rixml.DataTypes" />
 </Namespaces>
 <Validation>
   <VerifyRequired>false</VerifyRequired>
 </Validation>
 <Transformation>
   <Deanonymize strict="false" />
 </Transformation>
</Configuration>
        var rixml = new Research
        {
            researchID = "my-id",
            createDateTime = DateTime.UtcNow,
            language = "eng",
            Product = new[]
            {
                new Product
                {
                    Content = new Content
                    {
                        Title = new Title
                        {
                            TypedValue = "My title"
                        }
                    }
                }
            }
        };

The model cannot be used due to the following errors:

  • Ambiguity between 'Product.Content' and 'Product.Content'
  • 'Content' : member names cannot be the same as their enclosing type

Guymestef avatar Aug 02 '22 14:08 Guymestef

Hello, thanks for reporting this.

To get around this, try to fully qualify the type name (not the class member), with it's CLR namespace.

the code generator does not have exhaustive logic to fully disambiguate type and member name clashes, so bugs like this happen on occasion.

mamift avatar Aug 04 '22 01:08 mamift

I'm sorry, can you please provide an example of what you mean by "try to fully qualify the type name (not the class member), with it's CLR namespace."

Thank you!

PMG-VascoSaavedra avatar Feb 08 '24 23:02 PMG-VascoSaavedra

I'm sorry, can you please provide an example of what you mean by "try to fully qualify the type name (not the class member), with it's CLR namespace."

So consider this; the type name might be ClassName or IInterfaceName, and it's namespace might be DefaultNs.

Fully qualified the above type names would be DefaultNs.IInterfaceName or DefaultNs.ClassName

To bring it back to the original post:

This:

Content = new Content
{
	Title = new Title
	{
		TypedValue = "My title"
	}
}

Should be this:

Content = new DefaultNs.Content
{
	Title = new Title
	{
		TypedValue = "My title"
	}
}

mamift avatar Feb 12 '24 01:02 mamift