If you have multiple XSDs containing duplicate elements you may run into issue when using Liquid XML Objects code generation.
Code Generator Warnings
If you have used the recommended approach for added multiple XSDs to a project, i.e. using a SchemaSet with the 'XML Data Access Model' option described here:
Then when you generate the Data Binding code, you will see any duplicate item issues reported in the Error List window during code generation and you will not be able to access these classes as they will not exist in the generated code:
1>C:\Temp\MySchema1.xsd(4,14,4,65): warning CS1030: #warning: 'A duplicate Element was found, it has been ignored.'
1>C:\Temp\MySchema2.xsd(4,14,4,65): warning CS1030: #warning: 'A duplicate Element was found, it has been ignored.'
If you have just added your XSDs to a project and generated code for each XSD individually, you will see compiler warnings for duplicate items:
Error CS0102 The type 'MySchema1.ResultsElm' already contains a definition for 'Value'
If instead, you added the XSDs individually into separate folders (and hence namespaces) and then generated code for each XSD, you will get an exception at runtime if you dynamically use the duplicate elements during Serialization as the runtime will not know which class to choose, for example:
LiquidTechnologies.XmlObjects.LxInvalidAttributionException: 3 classes are defined that describe the root xs:element <results /> . The classes are XmlDataModelProject1.MySchema1.Ns.ResultsElm, XmlDataModelProject1.MySchema2.Ns.ResultsElm, XmlDataModelProject1.MySchema3.Ns.ResultsElm.
This can be worked around by only loading the definitions from a given schema into the LxSerializer, in this way it will not load duplicate definitions and will not raise errors.
1. The best way to do this is to generate each XSD into its own library. You can then access the classes in a generic manner when you create the Serializer using:
var xmlSerializer = new LxSerializer<T>(typeof(T).Assembly);
Where T is the data type you expect to serialise from your XML document.
2. If you only want to use one assembly, you can add the XSDs into separate folders (and hence namespaces) within a single project and then filter the type you require by namespace as follows when you create the Serializer:
var xmlSerializer = new LxSerializer<T>(type => type.Namespace.StartsWith("XmlDataModelProject1.MySchema1"));