简体   繁体   中英

Getting an error specified method is not supported

I have a linq code like below

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) . I am getting an error like "specified method is not supported" .

Stack trace is

at Microsoft.SharePoint.Client.ClientQueryable'1.GetEnumerator()

at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)

at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)

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() (...)

I've written this code and it works on Windows Server environment, but on my Windows 10 computer not:

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;

I found it here

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. To get around this convert it from a Sharepoint collection to a generic list with another .ToList() as below.

Try:

itemCol.ToList()
   .Where(x => Convert.ToString(x[internalColumn]) == filter)
   .Select(x => x[internalColumn].ToString())
   .Distinct()
   .ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM