문제

I'm using client object model to migrate data from some external data source. The problem is that when I set lookup (normal list or user) I get:

Value does not fall within the expected range.

I set it like this:

//usr is an instance of User, and it exsists
item["Author"] = new FieldUserValue() { LookupId = usr.Id };

//this also fails, source is int, an ID of item in the lookup list that exists
item["DocumentSource"] = new FieldLookupValue() { LookupId = source };

The funny thing is that first 3 lookups doesn' throw exception. I set about 10 fields.

So, all lookup values exsits, first 2 or 3 user lookups run ok, when I uncomment any of the other 3 it throws exception. Anybody know what could be wrong? Does Client OM have some restrictions? I call context.ExecuteQuery() only once, after I set all fields.

edit: even if I comment out first 2 lookups it fails to execute.

edit: stack trace added

at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at MyClass.Run() in Path\To\My\File.cs:line 364
//MyClass is the class name and path is the path to my file...
도움이 되었습니까?

해결책

I've found that updating Lookup fields via the Client Object Model appears to be limited by the View Lookup Threshold setting in the Resource Throttling settings for your web app (central administration). If your limit is 8, updating 8 fields will work, but 9 will fail with the Value does not fall within the expected range. error. This is likely due to the ListItem "reloading" the fields once the update has been done (refreshing itself) and hitting the limit. Updating only a subset of the fields (say, 5 out of 9) works perfectly.

I'm going to open a ticket with MS support and see what they can tell us about this issue. There are significant considerations to bypassing this behavior by performing multiple updates, especially in scenarios with versions enabled.

다른 팁

I'm unable to reproduce your issue. I've tried using a list with 6 lookups and set them all plus Author:

var context = new ClientContext("http://aasp2010ifa:41000/sites/docid2");
var web = context.Web;
var list = web.Lists.GetByTitle("TestLookup");
var item = list.AddItem(new ListItemCreationInformation());
item["Look"] = new FieldLookupValue {LookupId = 1};
item["Look2"] = new FieldLookupValue {LookupId = 2};
item["Look3"] = new FieldLookupValue {LookupId = 3};
item["Look4"] = new FieldLookupValue {LookupId = 2};
item["Look5"] = new FieldLookupValue {LookupId = 3};
item["Author"] = new FieldLookupValue {LookupId = 9};
item.Update();
context.ExecuteQuery();

Try stripping back your code to something that works, or please provide a more complete code sample that we can reproduce.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top