LinqToXsdCore
                                
                                 LinqToXsdCore copied to clipboard
                                
                                    LinqToXsdCore copied to clipboard
                            
                            
                            
                        Generated code doesn't compile if an element is named Content
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
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.
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!
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"
	}
}