gpt4 book ai didi

c# - 从 DocumentDB 读取文档时出现关于 "Partition Routing Information"的异常

转载 作者:行者123 更新时间:2023-11-30 20:32:39 25 4
gpt4 key购买 nike

你见过这种异常信息吗?

Partition routing information cannot be extracted from the query when running in a 32-bit process. To complete your query and avoid this exception, ensure that your host process is 64-bit. For Executable applications, this can be done by unchecking the "Prefer 32-bit" option in the project properties window, on the Build tab. For VSTest based test projects, this can be done by selecting Test->Test Settings->Default Processor Architecture as X64, from Visual Studio Test menu option. For locally deployed ASP.NET Web applications, this can be done by checking the "Use the 64 bit version of IIS Express for web sites and projects", under Tools->Options->Projects and Solutions->Web Projects.

当我想从 DocumentDB 中读取文档时,我收到此异常消息。 C# 中检索文档的代码如下所示(也检查了没有 FeedOption 的情况):

FeedOptions queryOptions = new FeedOptions { EnableCrossPartitionQuery = true };
var conv = db.Client.CreateDocumentQuery<Model.Conversation>(
UriFactory.CreateDocumentCollectionUri(db.DatabaseName, db.CollectionName), queryOptions)
.Where(f => f.Id == "conversationId");

// the exception happens here
foreach(Conversation f in conv)
{
Debug.Print(f.Name);
}

在上面,db 是一个存储库,我确信 Client 已正确启动,因为我可以同时将文档插入 DocumentDB。

此外,您还可以看到 Conversation 模型:

public class Conversation
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
public string Name { get; set; }
[JsonProperty("cid")]
public string CID { get; set; } // defined as a partition key
}

我应该提一下,在 DocumentDB 中有一个带有 Id == "conversationId" 的文档,下面的代码在这种情况下有效,但这不是我想查询的解决方案Name 属性,而不仅仅是 Id:

Document doc = await db.Client.ReadDocumentAsync(
UriFactory.CreateDocumentUri(db.DatabaseName, db.CollectionName, "conversationId"),
new RequestOptions { PartitionKey = new PartitionKey("partitionKey") });
Conversation conv = (Conversation)(dynamic)doc;

最佳答案

它是程序集版本问题和异常,也显示了可能的修复解决方案。

修复该问题有三种可能的替代方法。

  1. 在 VS2015 中更改项目设置 -> 工具 -> 选项 - 项目和解决方案 -> Web 项目并勾选“使用 64 位版本的 IIS ...”

enter image description here

  1. 您可以更改 IIS 池设置并允许 32 位应用程序,如下图所示。

enter image description here

  1. 您还可以更改项目构建属性并将目标平台设置为“任何 CPU”。

enter image description here

关于c# - 从 DocumentDB 读取文档时出现关于 "Partition Routing Information"的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41104051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com