Cannot implicitly convert type 'ServiceReference1.StockData[] ' to Systems.Collections.Generic.List<StockData>

.net, asp.net, c#, wcf

Solution

When you added the reference to your site then under `DataType` ==> `Collection Type` you specified `System.Array`, (which is default as well), that is why your proxy is returning you an array instead of list.

When adding reference to the web service go to advance and specify `System.Collection.Generic.List` and you will get the same return type as in your contract.

But if you don't want to do that you can still use the Array and convert it to List using `ToList`

EDIT:

Like:

List<StockData> list = new List<StockData>();
list=(myProxy.orderStockData(txtinput1.Text, txtinput2.Text, txtinput3.Text)).ToList();

Problem

I'm trying to consume a WCF service that returns a custom list in the form `List<StockData>`. Here's the method signature from `IService.cs`: ``` [OperationContract] List<StockData> orderStockData(string compName1, string compName2, string compName3); ``` But when I try referencing it in my website through a service reference: ``` List<StockData> list = new List<StockData>(); list = myProxy.orderStockData(txtinput1.Text, txtinput2.Text, txtinput3.Text); ``` I get the following error: Cannot implicitly convert type 'ServiceReference1.StockData[] ' to Systems.Collections.Generic.List Any help with solving this would be great. Thanks!

Original source

Related problems