Thursday, 28 February 2013

Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'SomeType' to 'SomeType[]'

Problem

Recently I faced a problem while accessing a webservice, I added web reference in my Visual Studio project, and created an instance of a class, and it returned me error which was something like :

Unable to generate a temporary class (result=1).
error CS0029: Cannot implicitly convert type 'SomeType' to 'SomeType[]'

-SomeType = any class name available in the Service being consumed

Solution

After some efforts and googling, I found that this is one of the known bugs of  .NET. This problem was due to a type which was structured / mapped as dynamic array, like SomeType[][]. and the consumer of such properties data type was expecting a simple SomeType Object. 

What I did, I created a local class strucutre for the WSDL file and added that file in my project. To create a code file / class for the WSDL file , you need to follow these steps:
1. Start Command Prompt of Visual Studio ( try to run as administrator)

2. Type following command :
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>wsdl /o:d:\\referencefile
.cs http://server/ServiceFile.wsdl
3. It will create the dot cs file at the location specified in the above command, copy the file and add it in your project. 
4.Remove the web reference from the project.
5.From the CS file genereated find / search for double square brackets "[][]" for SomeType / Class name for which exception is being thrown, and change it to single square pair "[]". Save and compile.

Now it must now throw exeception. Hope that helps some one. ;-)


6 comments:

  1. I am getting these two errors while implementing your cmd prompt command. Can you guide me that what type of these errors are?

    There was an error downloading http://server/ServiceFile.wsdl
    the remote name could not be resolved : 'Server'

    ReplyDelete
    Replies
    1. Web service calling issue is fixed. But when i remove and add new reference file in the project. And remove the online web service file. The code shows me error. How can i call my reference file which will replace the online file. after removing [][] with [] this.

      Delete
    2. You just need to create object of the Class you have added in the project. and call functions then.
      BTW what error are you getting?

      Delete