Reputation: 630
Error Cannot implicitly convert type 'string[]' to 'System.Collections.Generic.List<string>'
The above error is caused when I call a method to a web service
List<string> bob = myService.GetAllList();
Where: GetAllList =
[WebMethod]
public List<string> GetAllList()
{
List<string> list ....
return list;
}
I have rebuilt the whole solution, updated the service references and still I get a cast exception any ideas?
Upvotes: 1
Views: 989
Reputation: 22368
The SOAP protocol doesn't support generic collections.
Try this instead:
List<string> bob = new List<string>(myService.GetAllList());
Upvotes: 1
Reputation: 10764
you need to do this:
List<string> bob = new List<string>(myService.GetAllList());
An overload for the constructor of a generic list takes an IEnumerable of the specified type to initialize the array. You can not, like the exception states, implicitly cast it staright to that type.
Andrew
Upvotes: 5