Cod*_*key 1 .net c# serialization web-services exception
Error Cannot implicitly convert type 'string[]' to 'System.Collections.Generic.List<string>'
Run Code Online (Sandbox Code Playgroud)
当我将方法调用到Web服务时,会导致上述错误
List<string> bob = myService.GetAllList();
Run Code Online (Sandbox Code Playgroud)
其中:GetAllList =
[WebMethod]
public List<string> GetAllList()
{
List<string> list ....
return list;
}
Run Code Online (Sandbox Code Playgroud)
我已经重建了整个解决方案,更新了服务引用,但我仍然得到任何想法的演员异常?
你需要这样做:
List<string> bob = new List<string>(myService.GetAllList());
Run Code Online (Sandbox Code Playgroud)
泛型列表的构造函数的重载采用指定类型的IEnumerable来初始化数组.像异常状态一样,你不能隐式地将它直接转换为该类型.
安德鲁