2

I'm attempting to update a Visual Studio web reference from using the v27.0 Metadata API to the Summer 13 v28.0 API.

This compiles fine, but when running the code an exception is thrown in the MetaDataService (instance of System.Web.Services.Protocols.SoapHttpClientProtocol) constructor.

System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type
'Foo.SalesforceMetadata.QuickActionLayoutItem[]' to 'Foo.SalesforceMetadata.QuickActionLayoutItem'

StackTrace:

  1. System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
  2. System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
  3. System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
  4. System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
  5. System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
  6. System.Web.Services.Protocols.SoapClientType..ctor(Type type)
  7. System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
  8. Foo.SalesforceMetadata.MetadataService..ctor() in D:\Development\Foo\Web References\SalesforceMetadata\Reference.cs: line 64

Note that this isn't a user permissions issue for the XML serialisation. It works just fine with the v27.0 API.

How can I use the v28.0 Metadata API from .NET?

1 Answer 1

5

The following lines in the WSDL are the cause of the issue:

<xsd:complexType name="QuickActionLayoutColumn">
  <xsd:sequence>
     <xsd:element name="quickActionLayoutItems" minOccurs="0" maxOccurs="unbounded" type="tns:QuickActionLayoutItem"/>
  </xsd:sequence>
</xsd:complexType>

It's a known bug that won't be fixed - Microsoft Connect: XmlSerializer Code Generation component cannot handle nested unbounded elements when there is only one element

The workaround was to inject a dummy attribute into the WSDL to bypass the bug.

<xsd:complexType name="QuickActionLayoutColumn">
  <xsd:sequence>
     <xsd:element name="quickActionLayoutItems" minOccurs="0" maxOccurs="unbounded" type="tns:QuickActionLayoutItem"/>
  </xsd:sequence>
  <xsd:attribute name="tmp" type="xsd:string" />
</xsd:complexType>

Alternatively you can modify the XmlArrayItemAttribute for quickActionLayoutColumns in the generated References.cs file. Modify the typeof(QuickActionLayoutItem) to be typeof(QuickActionLayoutItem[]).

See details in Importing the Salesforce Winter 13 Metadata API to .NET

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .