Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I correctly modify a generated XSD to overcome a known .Net bug that causes exception "cs0030:Unable to generate a temporary class"

I have been tasked to send data to a 3rd Party web service, they have provided a test service that is proven to work with a Java client, however, it doesn't in .Net.

When I generate the service proxy and either instantiate the service or serialise the request object, I get the following error:

Unable to generate a temporary class (result=1). 
error CS0030: Cannot convert type 'TestStarXML.wsStarService.VSOptionInclusiveSetType[]' to 'TestStarXML.wsStarService.VSOptionInclusiveSetType' 
error CS0030: Cannot convert type 'TestStarXML.wsStarService.VSOptionConflictSetType[]' to 'TestStarXML.wsStarService.VSOptionConflictSetType'
error CS0030: Cannot convert type 'TestStarXML.wsStarService.ColorRequirementSetType[]' to 'TestStarXML.wsStarService.ColorRequirementSetType' 
error CS0030: Cannot convert type 'TestStarXML.wsStarService.ColorExclusionSetType[]' to 'TestStarXML.wsStarService.ColorExclusionSetType' 
error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.VSOptionInclusiveSetType' to 'TestStarXML.wsStarService.VSOptionInclusiveSetType[]' 
error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.VSOptionConflictSetType' to 'TestStarXML.wsStarService.VSOptionConflictSetType[]' 
error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.ColorRequirementSetType' to 'TestStarXML.wsStarService.ColorRequirementSetType[]' 
error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.ColorExclusionSetType' to 'TestStarXML.wsStarService.ColorExclusionSetType[]'

The 3rd Party that sent us this service uses Java, and they had no problem generating the service proxy from the test service. My understanding so far is that there is a bug in .Net (see here) generating the XSD for the WSDL file.

In the answer here, it mentions modifying the generated XSD with dummy attributes, so I added the dummy attribute as suggested:

<xs:complexType name="VSInclusivesOptionType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="VSOptionInclusiveSet" type="tns:VSOptionInclusiveSetType" />
    </xs:sequence>
    <xs:attribute name="tmp" type="xs:string" />   <!-- this is all I have added (for each of the types in the exception message) -->
  </xs:complexType>
  <xs:complexType name="VSOptionInclusiveSetType">
    <xs:sequence>
      <xs:element minOccurs="0" name="SetID" type="ns2:IdentifierType" />
      <xs:element minOccurs="0" name="NumberOfOptionsNumeric" type="xs:decimal" />
      <xs:element minOccurs="0" maxOccurs="unbounded" name="VSOption2" type="tns:VSOption2Type" />
    </xs:sequence>
  </xs:complexType>

The only thing adding the dummy attribute achieved was to reduce the compile time of the project from minutes to seconds.

Other than this, VS2008 didn't seem to notice the changes - I still can't serialise the object or instantiate the service without getting the exception mentioned above, what am I missing or doing wrong?

like image 323
Mr Shoubs Avatar asked May 09 '12 11:05

Mr Shoubs


1 Answers

You have to change the XSD file as in my question, but you ALSO have to modify the Reference.cs (or .vb) file in the same folder - I did a find replace on [][] with [] (or ()() with () in vb.net).

In all the reading I've done, no answers have said to do both, so I just missed the point - I hope this answer helps others.

like image 193
Mr Shoubs Avatar answered Oct 24 '22 10:10

Mr Shoubs