element name="Content" causes error

Apr 19, 2011 at 2:40 PM


I have an xsd that contains

<xs:element name="Content" type="ContentType">
		<xs:documentation>The top-level element of the Content section.</xs:documentation>

When I use LinqToXSD.exe to generate a .cs class I get a class like the following

public partial class Content : XTypedElement, IXMetaData {
        //... other code ...

        public ContentType Content {
            get {
                return ContentField;

        //... other code ...

On compile this will cause the error:

'Content':member names cannot be the same as their enclosing type.

It looks like LinqToXSD.exe inserts this 'Content' property by convention. Thus if the element name is called 'Content' there is a conflict.

Can you confirm whether this is the case, if so could it be changed?


Apr 20, 2011 at 2:21 PM

LinqToXSD indeed has no check on this compiler constraint...

May 5, 2011 at 10:37 AM

I imagine this is a convention thats quite hard to break/fix. Can anything be done about it?

May 6, 2011 at 8:58 AM

I guess in this case you have to change the XSD or fix this in code. It should be quite easy to fix this actually; You only have to check whether your parent has the same name, if so prefix the child.