简体   繁体   English

获取“无法隐式转换类型'表[]'到'Generic.List <>'

[英]Getting a "Cannot implicitly convert type 'Tables[]' to 'Generic.List<>'

A few years ago I wrote a WCF service, which runs on a Windows 2003 server under IIS. 几年前,我写了一个WCF服务,它运行在IIS下的Windows 2003服务器上。 I wrote it using VS 2008, and .NET 3.5. 我用VS 2008和.NET 3.5编写了它。 The code in question is this: 有问题的代码是这样的:

public static List<ASILookupTables> GetLookupTableAux(bool UseProduction)
{
ASIClassesDataContext dcASI = new ASIClassesDataContext();

var result = from lookups in dcASI.ASILookupTables4s
                         orderby lookups.SortOrder
                         select lookups;

List<ASILookupTables> list = new List<ASILookupTables>();

foreach (var item in result)
{
    ASILookupTables alt = new ASILookupTables();
    //more lines to add other elements
    list.Add(alt);
}

return list;
}

Now I'm writing a VS 2010 app, using .NET 4.0, to consume this. 现在我正在编写一个使用.NET 4.0的VS 2010应用程序来使用它。 The code snippet in question in the VS 2010 app is this: VS 2010应用程序中的代码片段如下:

            LookupSvc.LookupsClient proxy = new LookupSvc.LookupsClient();

        //retrieve list of lookup tables
        List<LookupSvc.ASILookupTables> lookupTables = proxy.GetLookupTableAux(true);

However, I'm getting the following error: 但是,我收到以下错误:

"Cannot implicitiy convert type 'AsiEF.LookupSvc.ASILookupTables[]' to 'System.Collections.Generic.List'" “无法将类型'AsiEF.LookupSvc.ASILookupTables []'隐式转换为'System.Collections.Generic.List'”

I don't get it; 我不明白; in the WCF code it looks to me like I'm returning a list. 在WCF代码中它看起来像我正在返回一个列表。 It doesn't look like I'm returning an array. 它看起来不像我正在返回一个数组。 Is it because the WCF service is in .NET 3.5 and my new project is in .NET 4.0? 是因为WCF服务是在.NET 3.5中而我的新项目是在.NET 4.0中吗?

You can change in the service reference settings if you want the proxy to use List<T> or T[] . 如果希望代理使用List<T>T[] ,则可以更改服务引用设置。

To change the settings, right click the service reference in the project in solution explorer. 要更改设置,请右键单击解决方案资源管理器中项目中的服务引用。 Pick "Configure Service Reference". 选择“配置服务参考”。 In "Collection type" pick System.Collections.Generic.List . 在“Collection type”中选择System.Collections.Generic.List

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法转换Generic.List <AnonymousType#1> 到Generic.List <BillEF.Bill> - Cannot convert Generic.List<AnonymousType#1> to Generic.List<BillEF.Bill> 无法将类型隐式转换为System.Collections.Generic.List - Cannot implicitly Convert type to System.Collections.Generic.List 无法将类型 Collections.Generic.List 隐式转换为 System.Collections.Generic.IEnumerable - Cannot implicitly convert type Collections.Generic.List to System.Collections.Generic.IEnumerable 无法将类型'System.Collections.IList'隐式转换为'System.Collections.Generic.List - Cannot implicitly convert type 'System.Collections.IList' to 'System.Collections.Generic.List 无法将类型&#39;ServiceReference1.StockData []&#39;隐式转换为Systems.Collections.Generic.List <StockData> - Cannot implicitly convert type 'ServiceReference1.StockData[] ' to Systems.Collections.Generic.List<StockData> 无法将类型隐式转换为 System.Collections.Generic.List 到 System.DateTime - Cannot implicitly convert type to System.Collections.Generic.List to System.DateTime 无法将类型void隐式转换为List - Cannot implicitly convert type void to List 无法将派生类型隐式转换为其基本泛型类型 - Cannot implicitly convert derived type to its base generic type 无法将派生类型隐式转换为其基本通用类型- - Cannot implicitly convert derived type to its base generic type - 无法隐式转换类型&#39;System.Collections.Generic.List <System.Data.DataRow> &#39;到&#39;System.Collections.Generic.List <string> &#39; - Cannot implicitly convert type 'System.Collections.Generic.List<System.Data.DataRow>' to 'System.Collections.Generic.List<string>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM