[英]Getting an error specified method is not supported
I have a linq code like below我有一个像下面这样的 linq 代码
itemCol.Where(x => Convert.ToString(x[internalColumn]) == filter)
.Select(x => x[internalColumn].ToString())
.Distinct()
.ToList();
itemCol
is a Sharepoint List Item collection in managed CSOM (ListItemCollection) . itemCol
是托管 CSOM (ListItemCollection) 中的 Sharepoint 列表项集合。 I am getting an error like "specified method is not supported" .我收到类似“不支持指定方法”的错误消息。
Stack trace is堆栈跟踪是
at Microsoft.SharePoint.Client.ClientQueryable'1.GetEnumerator()
在 Microsoft.SharePoint.Client.ClientQueryable'1.GetEnumerator()
at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)
在 System.Collections.Generic.List'1..ctor(IEnumerable'1 集合)
at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable'1 源)
This issue is happening in client machine alone not in any dev machines.这个问题只发生在客户端机器上,而不是任何开发机器上。
I had similar problem我有类似的问题
Specified method is not supported stacktrace: Microsoft.SharePoint.Client.ClientQueryable`1.GetEnumerator() (...)
不支持指定的方法堆栈跟踪:Microsoft.SharePoint.Client.ClientQueryable`1.GetEnumerator() (...)
I've written this code and it works on Windows Server environment, but on my Windows 10 computer not:我编写了这段代码,它适用于 Windows Server 环境,但不适用于我的 Windows 10 计算机:
SP.ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem, (....)
clientContext.ExecuteQuery();
var outlist = (collListItem
.Select(item => new MyClass()
{
ID = Convert.ToInt32(item["ID"])
}) as IEnumerable<MyClass>)
.ToList();
return outlist;
I've resolved it adding parsing collection to list before select like this:我已经解决了在选择之前将解析集合添加到列表的问题,如下所示:
SP.ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem, (....)
clientContext.ExecuteQuery();
var outlist = (collListItem.ToList()
.Select(item => new MyClass()
{
ID = Convert.ToInt32(item["ID"])
}) as IEnumerable<MyClass>)
.ToList();
return outlist;
See Stephen Turner's answer .见斯蒂芬·特纳的回答。 As he wrote:
正如他所写:
The issue is being caused because the Sharepoint collection type doesn't support the full range of Linq expressions.
导致此问题的原因是 Sharepoint 集合类型不支持所有 Linq 表达式。 To get around this convert it from a Sharepoint collection to a generic list with another
.ToList()
as below.为了解决这个问题,将它从 Sharepoint 集合转换为具有另一个
.ToList()
的通用列表,如下所示。
Try:尝试:
itemCol.ToList()
.Where(x => Convert.ToString(x[internalColumn]) == filter)
.Select(x => x[internalColumn].ToString())
.Distinct()
.ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.