0

I have 2 XSD files A.xsd and B.xsd and both of them importing a common xsd file C.xsd , upon converting them to C# files using XSD.exe, both of them has classes incuding the classes from C.XSd (common XSD)

Sample Code: first c# file from xsd 1:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="xyz")]
   public partial class ABC  {
       }

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="xyz")]
            public partial class ABC  {
             }

This is causing a run time error :

Types 'First C# file.ABC' and 'Second C# file.ABC' both use the XML type name, 'ABC', from namespace 'xyz'. Use XML attributes to specify a unique XML name and/or namespace for the type

I do not want to change the namespace as the complex types form third party XSD maps to this namespace.

I tried TypeName Attribute, but this seems to not work.

Please help me to on this situation.

I am running xsd.exe twice because A.xsd and B.xsd are huge files and running them in a single command would result in huge single auto generated C# file, so I wanted to generate separate C# classes for A.xsd and B.xsd.

dbc
  • 104,963
  • 20
  • 228
  • 340
Sudheer
  • 11
  • grammar, formatting – teunbrand Aug 08 '19 at 17:35
  • What happens if you try [`SvcUtil.exe /serializer:XmlSerializer`](https://learn.microsoft.com/en-us/dotnet/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe)? – dbc Aug 08 '19 at 19:35
  • Also, exactly how are you invoking `xsd.exe`? Can you show your command line and some simplified XSDs that reproduce the problem? – dbc Aug 08 '19 at 19:40
  • Hello, Thank you for the response, I used following commands > xsd /c common.xsd B.xsd > xsd /c common.xsd A.xsd – Sudheer Aug 09 '19 at 09:03
  • Common.xsd: – Sudheer Aug 09 '19 at 09:05
  • Looks like you are running `xsd.exe` twice, thereby generating duplicate versions of the common types. What if you run it only once and pass in all the schema files on the command line? `xsd.exe /c common.xsd B.xsd A.xsd` – dbc Aug 09 '19 at 22:20
  • Hello Again, Agree with you, but that will generate a single auto generated C# file. A.xsd and B.xsd are huge files and running them in a single command would result in huge single auto generated C# file, So I wanted to generate separate C# classes for A.xsd and B.xsd Apologies for not mentioning this before – Sudheer Aug 12 '19 at 05:28
  • Then see [Create MULTIPLE class files based on an XSD](https://stackoverflow.com/q/6654763/3744182). In fact this appears to be a duplicate, agree? – dbc Aug 12 '19 at 20:48
  • 1
    Agree this seems duplicate.. Your last two replies answered my complete question ... Thanks a lot for your help on this issue – Sudheer Aug 13 '19 at 05:20

0 Answers0