首页 > 解决方案 > UWP 应用 CosmosDb 构造器抛出错误

问题描述

我有一个我以前从未见过的错误。在我的 CosmosDb DocumentClient 构造函数中:

docClient = new DocumentClient(new 
  Uri("https://docdb.documents.azure.com:443/"),
    "key_here",new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, 
        ConnectionProtocol = Protocol.Tcp });

当我设置断点时,它会引发此错误:

 A type initializer threw an exception. To determine which type, 
 inspect the InnerException's StackTrace property.

InnerException 的堆栈跟踪:

Severity    Code    Description Project File    Line    Suppression State
Warning     MCG : warning MCG0007: Unresolved P/Invoke method 
'DocumentDB.LogStoreViewer.dll!FreeIOManager' 
for method 'System.Int32 


Microsoft.Azure.Documents.LogStoreViewerInterop.
LogStoreViewerInteropWrapper.
FreeIOManager(System.IntPtr)'.
Calling this method would throw exception at runtime. Please make sure the 
P/Invoke either points to a Windows API allowed in UWP applications, 
or a native DLL that is part of the package. If for some reason your 
P/Invoke does not satisfy those requirements, 
please use [DllImport(ExactSpelling=true) to indicate that you understand 
the implications of using non-UWP APIs.

在我的项目中,我引用了一个 .Net Standard 2.0 类库。根据错误信息,它看起来像

 Microsoft.Azure.Documents.LogStoreViewerInterop.
 LogStoreViewerInteropWrapper.
 FreeIOManager(System.IntPtr)'.

我找不到这个来删除它或理解它的作用,所以不知道如何治愈这个邪恶的东西。

标签: c#uwpazure-cosmosdbvisual-studio-2019

解决方案


推荐阅读