views:

307

answers:

2
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?

+5  A: 

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

REA_ANDREW
+1  A: 

The SOAP protocol doesn't support generic collections.

Try this instead:

List<string> bob = new List<string>(myService.GetAllList());
Gerrie Schenck