Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SharePoint CSOM(可移植)进行搜索时引发异常_C#_Windows Store Apps_Sharepoint 2013_Csom_Sharepoint Search - Fatal编程技术网

C# 使用SharePoint CSOM(可移植)进行搜索时引发异常

C# 使用SharePoint CSOM(可移植)进行搜索时引发异常,c#,windows-store-apps,sharepoint-2013,csom,sharepoint-search,C#,Windows Store Apps,Sharepoint 2013,Csom,Sharepoint Search,我正在尝试使用SharePoint客户端框架执行搜索,使用Windows应用程序中的可移植dll 使用Fiddler,我可以看到我的搜索已执行,并返回元数据和搜索结果的JSON集合。这与非便携式CSOM的结果相同 当CSOM尝试将结果映射到它的数据对象时,我得到以下异常: 无法将类型为“System.Collections.Generic.Dictionary`2[System.String,System.object]”的对象强制转换为类型为“Microsoft.SharePoint.Clie

我正在尝试使用SharePoint客户端框架执行搜索,使用Windows应用程序中的可移植dll

使用Fiddler,我可以看到我的搜索已执行,并返回元数据和搜索结果的JSON集合。这与非便携式CSOM的结果相同

当CSOM尝试将结果映射到它的数据对象时,我得到以下异常:

无法将类型为“System.Collections.Generic.Dictionary`2[System.String,System.object]”的对象强制转换为类型为“Microsoft.SharePoint.Client.Search.Query.ResultableCollection”

此异常发生在CSOM(可移植)内部。非可移植CSOM运行无异常,并返回预期结果

我正在运行以获取此异常的代码是:

var query = new KeywordQuery(ctx);
query.QueryText = "something";
var executor = new SearchExecutor(ctx);
var results = executor.ExecuteQuery(query);
await ctx.ExecuteQueryAsync();
在上面,ctx是一个已经过身份验证的ClientContext。其他请求(如获取特定列表)按预期工作

我正在引用c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI中的以下dll:

  • Microsoft.SharePoint.Client.Portable.dll
  • Microsoft.SharePoint.Client.Runtime.Portable.dll
  • Microsoft.SharePoint.Client.Runtime.WindowsStore.dll
  • Microsoft.SharePoint.Client.Search.Portable.dll
我的问题是

如何解决这个问题,以便使用CSOM从Windows应用商店应用程序运行搜索查询

更新: 在验证ClientContext后,我添加了以下内容:

ctx.ExecutingWebRequest += (s, e) =>
    e.WebRequest.Headers["Accept-Encoding"] = "gzip, deflate";
这解决了眼前的问题,但引入了一个新的问题。我现在得到一个System.FormatException:

格式不好的JSON流


由于可移植和非可移植CSOM中的JSON是相同的,因此在一个CSOM中不应该存在解析错误,而在另一个CSOM中不应该存在解析错误。

我可以从您的异常中发现,强制执行查询结果会在此处产生问题

使用下面的代码强制转换执行查询结果

ResultTable rtSharePointSearchResult = new ResultTable();
KeywordQuery query = new KeywordQuery(clientContext);
query.QueryText = "Keywords";
query.TrimDuplicates = false;
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(query);
clientContext.ExecuteQuery();
rtSharePointSearchResult = results.Value[0];
ResultTable rtSharePointSearchResult=新的ResultTable();
关键字查询=新关键字查询(clientContext);
query.QueryText=“关键字”;
query.TrimDuplicates=false;
SearchExecutor SearchExecutor=新的SearchExecutor(clientContext);
ClientResult results=searchExecutor.ExecuteQuery(查询);
clientContext.ExecuteQuery();
rtSharePointSearchResult=results.Value[0];

请注意,第一篇文章使用了ctx.ExecuteQueryAsync,但“答案”使用了ctx.ExecuteQuery

bug在可移植类库(第一篇文章使用)中,但在非可移植版本(第二篇文章)中有效

干杯, 保罗