Linq2Xsd 1.1.0, generated code properties missing namespaces

Jun 29, 2011 at 3:05 PM

Hi,

Huge problem with Linq2Xsd 1.1.0 for us, some 3rd party schemas are generating broken code.

And as it's 3rd party, there is nothing we can do about the schema.

Here's is one of the offending parts of the schema:

 

<xs:complexType name="LAADJReportType">
		<xs:annotation>
			<xs:documentation>Notification of cases adjourned report type</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="ReportTemplate">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:whiteSpace value="preserve"/>
						<xs:enumeration value="PASLAADJ"/>
						<xs:enumeration value="CONLAADJ"/>
						<xs:enumeration value="BUSLAADJ"/>
						<xs:enumeration value="MOVLAADJ"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
			<xs:element name="ReportName" type="ReportNameEnum"/>
			<xs:element name="ReportDate" type="xs:date"/>
			<xs:element name="Cases">
				<xs:complexType>
					<xs:sequence>
						<xs:element name="Case" minOccurs="0" maxOccurs="unbounded">
							<xs:complexType>
								<xs:sequence>
									<xs:element name="CRN">
										<xs:simpleType>
											<xs:restriction base="xs:string">
												<xs:whiteSpace value="preserve"/>
											</xs:restriction>
										</xs:simpleType>
									</xs:element>
									<xs:element name="PCNs" type="PCNsType"/>
									<xs:element name="NewScheduledDate" type="xs:dateTime"/>
									<xs:element name="CaseType" type="CaseTypeEnum"/>
									<xs:element name="ToBeCompletedBy" type="xs:date"/>
									<xs:element name="GroundsOfAppeal" type="GroundsOfAppealEnum"/>
									<xs:element name="AdjournmentNotes">
										<xs:simpleType>
											<xs:restriction base="xs:string">
												<xs:whiteSpace value="preserve"/>
											</xs:restriction>
										</xs:simpleType>
									</xs:element>
								</xs:sequence>
							</xs:complexType>
						</xs:element>
					</xs:sequence>
					<xs:attribute name="NoOfCases" type="xs:integer" use="required"/>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>

 

 

Some, but not all, of the C# properties generated for that local type are broken, the first one we came up against was Cases:

 

        public CasesLocalType Cases {
            get {
                XElement x = this.GetElement(XName.Get("Cases", ""));
                return ((CasesLocalType)(x));
            }
            set {
                this.SetElement(XName.Get("Cases", ""), value);
            }
        }

 

Note the empty namespace in XName.Get("Cases", "")

This should be: XName.Get("Cases", "http://www.someco.com/SomeNameSpace")

It works on some of the properties:

 

        public System.DateTime ReportDate {
            get {
                XElement x = this.GetElement(XName.Get("ReportDate", "NAMESPACEDELETED"));
                return XTypedServices.ParseValue<System.DateTime>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Date).Datatype);
            }
            set {
                this.SetElement(XName.Get("ReportDate", "NAMESPACEDELETED"), value, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Date).Datatype);
            }
        }

And not others:

 

        public string ReportTemplate {
            get {
                XElement x = this.GetElement(XName.Get("ReportTemplate", ""));
                return XTypedServices.ParseValue<string>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);
            }
            set {
                this.SetElementWithValidation(XName.Get("ReportTemplate", ""), value, "ReportTemplate", ReportTemplateLocalType.TypeDefinition);
            }
        }

 

We have a workaround, which is thus:

namespace namespace.deleted
{

    public partial class LAADJReportType : XTypedElement
    {
        /// <summary>
        /// <para>
        /// Occurrence: required
        /// </para>
        /// <para>
        /// Regular expression: (ReportTemplate, ReportName, ReportDate, Cases)
        /// </para>
        /// </summary>
        public namespace.deleted.LAADJReportType.CasesLocalType Cases2
        {
            get
            {
                XElement x = this.GetElement(XName.Get("Cases", "NAMESPACEDELETED"));
                return ((namespace.deleted.CasesLocalType)(x));
            }
            set
            {
                this.SetElement(XName.Get("Cases", "NAMESPACEDELTED"), value);
            }
        }
    }
}

Does anybody know what's going on? How to fix it?

I know there are newer versions of Linq2Xsd for .NET 4.0 out, do they contain further fixes or are they just recompiled for 4.0?

Are the .NET 3.5 version still going to be supported or are they now abandoned?

Regards,

J1M.