我尝试在针对Azure CosmosDb的F#脚本文件中测试一些不同的查询,但是当我尝试执行查询时,我收到有关丢失的DLL的错误。
我正在加载Documents.Client.dll
:
#r "../packages/Microsoft.Azure.DocumentDB/lib/net45/Microsoft.Azure.Documents.Client.dll"
open Microsoft.Azure.Documents
open Microsoft.Azure.Documents.Client
open Microsoft.Azure.Documents.Linq
但是当我执行查询时:
Seq.toList <| query {
//some query that I copy & pasted from a working file
}
我收到此错误:
System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.Azure.Documents.ServiceInteropWrapper.CreateServiceProvider(String configJsonString, IntPtr& serviceProvider)
at Microsoft.Azure.Documents.Query.QueryPartitionProvider.Initialize()
at Microsoft.Azure.Documents.Query.QueryPartitionProvider.GetPartitionedQueryExecutionInfoInternal(SqlQuerySpec querySpec, PartitionKeyDefinition partitionKeyDefinition, Boolean requireFormattableOrderByQuery, Boolean isContinuationExpected)
at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.<GetPartitionedQueryExecutionInfoAsync>d__0.MoveNext()
(堆栈跟踪中有更多 - 这只是它的顶部)。
我无法在任何地方找到ServiceInterop
dll - 它未在任何项目或我的包文件夹中引用,并且它不是nuget引用。我不确定在F#Interactive中只能得到这个错误。
更新
根据@ tomislav-markovski的评论中的建议,我将Microsoft.Azure.DocumentDB
的版本更改为1.13.2。这个 在包文件夹中创建ServiceInterop
dll,但是现在在F#interactive中运行我的查询会给出这个输出:
--> Referenced 'c:\VSTS\MyApplication\../packages/Microsoft.Azure.DocumentDB/lib/net45/Microsoft.Azure.Documents.Client.dll' (file may be locked by F# Interactive process)
Script.fsx(5,1): error FS0229: Error opening binary file 'c:\VSTS\MyApplication\../packages/Microsoft.Azure.DocumentDb/runtimes/win7-x64/native/Microsoft.Azure.Documents.ServiceInterop.dll': c:\VSTS\MyApplication\../packages/Micro
soft.Azure.DocumentDb/runtimes/win7-x64/native/Microsoft.Azure.Documents.ServiceInterop.dll: bad cli header, rva 0
Script.fsx(5,1): error FS3160: Problem reading assembly 'c:\VSTS\MyApplication\../packages/Microsoft.Azure.DocumentDb/runtimes/win7-x64/native/Microsoft.Azure.Documents.ServiceInterop.dll': Exception of type 'Microsoft.FSharp.Compiler.ErrorLogger+
StopProcessingExn' was thrown.
&#34;文件可能被锁定&#34;错误似乎很重要,但我关闭了&amp;重新打开VSCode以确保F#Interactive的实例不会保留任何内容。我 am 引用Service Interop文件:
#r "../packages/Microsoft.Azure.DocumentDb/runtimes/win7-x64/native/Microsoft.Azure.Documents.ServiceInterop.dll"
如果我删除了这个,上面的错误就会消失......然后我会回到查询本身崩溃,因为缺少了DLL。
更新2
我尝试过其他一些事情:
Client.dll
。这导致&#34;缺少服务interop dll&#34;错误。使用#I
加载DLL,路径更简单:
#I "../packages/Microsoft.Azure.DocumentDB/lib/net45/"
#r "Microsoft.Azure.Documents.Client.dll"
结果相同&#34;缺少ServiceInterop.dll
&#34;错误。
简化查询:
Seq.toList <| query {
for t in client.CreateDocumentQuery( documentCollectionUri()) do
select t
}
这导致了同样的错误ServiceInterop.dll
&#34;错误。
5.将FeedOptions与&#34;使用Cross Partiiton Query&#34;于:
let feedOptions = FeedOptions()
feedOptions.EnableCrossPartitionQuery <- true
feedOptions.MaxItemCount <- 3 |> System.Nullable
Seq.toList <| query {
for t in client.CreateDocumentQuery( documentCollectionUri(), feedOptions ) do
select t
}
如您所见,我也尝试设置最大项目数。这两个都给出了相同的&#34;缺少ServiceInterop.dll
&#34;错误。
答案 0 :(得分:0)
我能找到的最接近解决方案的是在FSI会话期间将ServiceInterop.dll的位置添加到Path环境变量,如下所示:
open System
open System.IO
// get existing contents of path env var
let path = Environment.GetEnvironmentVariable("Path")
// get location where nuget puts the service interop dll
let serviceInteropDir = @C:\User\<USERNAME>\.nuget\packages\microsoft.azure.documentdb.core\1.9.1\runtimes\win\native"
// add service interop location to the end of the path
let newPath = path + ";" + serviceInteropDir
// update the path env var with the new path
Environment.SetEnvironmentVariable("Path", newPath)
注意:请注意我使用的是DocumentDB.Core包的1.9.1版。 There seems to be a strong naming problem with the 1.10.0 version of the DocumentDB.Core package,请在发布修补程序或找到解决方法之前避免使用该版本。