在Visual Studio Mac上使用DocumentClient的TypeLoadException

时间:2017-06-01 14:48:32

标签: azure azure-cosmosdb visual-studio-mac

我从Azure Cosmos DB下载了入门示例应用程序,并且在Visual Studio Mac中出现以下错误

System.TypeLoadException: Could not resolve type with token 010000f6 (from typeref, class/assembly System.Diagnostics.Eventing.EventProviderTraceListener, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at Microsoft.Azure.Documents.Client.DocumentClient.Initialize (System.Uri serviceEndpoint, Microsoft.Azure.Documents.Client.ConnectionPolicy connectionPolicy, System.Nullable`1[T] desiredConsistencyLevel) [0x00014] in <f7f11c3ada88490092c73d6bef54be97>:0
  at Microsoft.Azure.Documents.Client.DocumentClient..ctor (System.Uri serviceEndpoint, System.String authKeyOrResourceToken, Microsoft.Azure.Documents.Client.ConnectionPolicy connectionPolicy, System.Nullable`1[T] desiredConsistencyLevel) [0x00069] in <f7f11c3ada88490092c73d6bef54be97>:0
  at GraphGetStarted.Program.Main (System.String[] args) [0x00021] in /DocumentDB-Quickstart-DotNet-Graph/GraphGetStarted/Program.cs:29

它失败的代码

   DocumentClient client = new DocumentClient(url, authKey, policy);

这是packages.config:我是否需要为Visual Studio Mac设置不同的targetFramework?

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Azure.DocumentDB" version="1.14.0" targetFramework="net452" />
  <package id="Microsoft.Azure.Graphs" version="0.2.0-preview" targetFramework="net452" />
  <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net452" />
  <package id="Microsoft.CodeAnalysis.Common" version="1.3.0" targetFramework="net452" />
  <package id="Microsoft.CodeAnalysis.CSharp" version="1.3.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
  <package id="System.Collections" version="4.3.0" targetFramework="net452" />
  <package id="System.Collections.Immutable" version="1.1.37" targetFramework="net452" />
  <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net452" />
  <package id="System.Globalization" version="4.3.0" targetFramework="net452" />
  <package id="System.Linq" version="4.3.0" targetFramework="net452" />
  <package id="System.Reflection.Metadata" version="1.2.0" targetFramework="net452" />
  <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net452" />
  <package id="System.Threading" version="4.3.0" targetFramework="net452" />
</packages>

2 个答案:

答案 0 :(得分:0)

我认为Protocol.Tcp不是.NET Core。你能尝试用

吗?

new ConnectionPolicy {ConnectionMode = ConnectionMode.Gateway,ConnectionProtocol = Protocol.Https}))

new ConnectionPolicy {ConnectionMode = ConnectionMode.Direct,ConnectionProtocol = Protocol.Https}))

谢谢!

答案 1 :(得分:0)

根据您的评论,您使用.net项目。请不要尝试在MacOS上运行.net项目。我们可以创建在Windows,Linux和macOS上运行的.NET Core个应用程序。我们还可以从官方tutorials获取有关azure DocumentDB和.NET Core的信息。