相关疑难解决方法(0)

找不到System.Net.Http 4.2.0.0的奇怪问题

我有一个奇怪的问题,这让我发疯...

我有一个简单的类库项目(完整的.NET Framework,4.6.1),其中包含围绕Cosmos DB的功能的包装类.因此,我已将"Microsoft.Azure.DocumentDB"NuGet Package 1.19.1添加到此项目中.除此之外,我引用了"Newtonsoft.Json"NuGet Package 10.0.3,以及一些"Microsoft.Diagnostics.EventFlow.*"NuGet包.

到目前为止,一切都编译没有任何错误.

但只要我点击我的包装类 - 从简单的Service Fabric无状态服务(完整的.NET Framework 4.6.1)中消耗 - 并尝试执行以下代码行:

_docClient = new DocumentClient(new Uri(cosmosDbEndpointUrl), cosmosDbAuthKey);
Run Code Online (Sandbox Code Playgroud)

我在运行时遇到这个奇怪的错误:

发生System.IO.FileNotFoundException HResult = 0x80070002
消息=无法加载文件或程序集'System.Net.Http,Version = 4.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.
Source = StackTrace:at Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri 1 desiredConsistencyLevel) at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, NullableserviceEndpoint ,ConnectionPolicy connectionPolicy,Nullable 1 desiredConsistencyLevel)

内部异常1:FileNotFoundException:无法加载文件或程序集'System.Net.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.

我完全没有线索,为什么根本找不到System.Net.Http程序集 - 我的类库项目中甚至有一个程序集引用到.Net Framework程序集"System.Net.Http 4.0.0.0".

我也不明白的是,有这种奇怪的绑定重定向到4.2.0.0 - 哪一个来自?为了解决这个问题,我尝试将以下重定向添加到Service Fabric Service的app.config(使用类库):

但仍然没有区别,我仍然在运行时得到错误.

有人知道吗?有人见过这样的问题吗?

谢谢和问候,OliverB

.net dotnet-httpclient visual-studio-2017 service-fabric-stateless

79
推荐指数
5
解决办法
4万
查看次数

找不到方法:'System.Collections.ObjectModel.Collection`1

嗨,当我发布它时,我在我的 WebService 上收到此跟随错误,

  • 找不到方法:'System.Collections.ObjectModel.Collection`1 System.Net.Http.Formatting.MediaTypeFormatter.get_SupportedMediaTypes()'。 在此处输入图片说明

但是当我在 VS 调试模式下使用它时,它不会发生。我已经在 google 上搜索过它并尝试在 webconfig 上使用程序集引用,但它没有任何提示?

这是我当前的 webconfig 文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
<system.web>
    <customErrors mode="Off"/>
</system.web>
<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>

  <system.web>
    <httpRuntime executionTimeout="3000000" maxRequestLength="1048576" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Windows" />
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
  <runtime>
       <dependentAssembly>
           <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
           <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0"/>
        </dependentAssembly>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" …
Run Code Online (Sandbox Code Playgroud)

c# web-services

2
推荐指数
1
解决办法
1945
查看次数