找不到System.Net.Http 4.2.0.0的奇怪问题 [英] Strange issue with System.Net.Http 4.2.0.0 not found

查看:1790
本文介绍了找不到System.Net.Http 4.2.0.0的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,这使我发疯……



我有一个带有包装类的简单类库项目(Full .NET Framework,4.6.1)有关Cosmos DB的功能。因此,我已向该项目添加了 Microsoft.Azure.DocumentDB NuGet软件包1.19.1。除此之外,我还引用了 Newtonsoft.Json NuGet软件包10.0.3,以及一些 Microsoft.Diagnostics.EventFlow。* NuGet软件包。



到目前为止,所有内容都可以编译,没有任何错误。



但是,一旦我碰到了包装器类,就从一个简单的Service Fabric无状态服务(Full)中消耗掉了。 NET Framework 4.6.1)–并尝试执行以下代码行:

  _docClient = new DocumentClient(new Uri(cosmosDbEndpointUrl ),cosmosDbAuthKey); 

运行时出现此奇怪错误:



< blockquote>

发生System.IO.FileNotFoundException HResult = 0x80070002

消息=无法加载文件或程序集'System.Net.Http,
Version = 4.2.0.0, Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或
其依赖项之一。系统找不到指定的文件。

Source = StackTrace:
处Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri
serviceEndpoint,ConnectionPolicy connectionPolicy,Nullable 1
期望的一致性级别)
Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri
serviceEndpoint,字符串authKeyOrResourceToken,ConnectionPolicy
connectionPolicy,可为空
1 requiredConsistencyLevel)



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


我绝对不知道,为什么System.Net.Http程序集是根本找不到–在我的类库项目中甚至有一个程序集引用到.Net Framework程序集 System.Net.Http 4.0.0.0。



我做什么还不明白的是,有一个奇怪的绑定重定向到4.2.0.0-那是哪里来的?
为了解决这个问题,我尝试将以下重定向添加到Service Fabric服务的app.config(正在消耗类库):








但是仍然没有区别,我仍然在运行时遇到错误。



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



谢谢,
OliverB

解决方案

您面临的问题与Visual Studio有关,尤其是与 System.Net.Http v4.2.0.0 一起提供的2017年。但是,采用新方法通过NuGet进行任何引用,最新版本的 System.Net.Http 的4.3.3版本包含dll版本4.1.1.2。 / p>

问题是VS在生成时和运行时也会忽略您的引用,而是会尝试引用它知道的DLL。



如何修复它:




  • 确保对系统的任何引用.Net.Http是通过NuGet完成的。​​

  • 构建时间错误:更改System.Net.Http.dll的扩展名(或将其移动到其他位置...基本上摆脱它)VS 2017( c:\Program Files(x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET。 Build.Extensions\net461\lib\ );如果您使用的是其他版本,则路径会略有不同,虽然不会太大

  • 运行时错误:添加程序集绑定重定向









如果您在Google上在线查看,则会发现与Microsoft有关的一些未解决问题,因此希望他们将来会解决此问题。



希望这会有所帮助。



更新:



在寻找此问题的永久解决方案时,在构建代理上工作,请注意,如果您迁移到新的NuGet PackageReference模型(在 .csproj 中,而不是在 packages.config )往往效果更好。这是有关如何进行此升级的指南的链接: https://docs.microsoft.com/zh-CN/nuget/reference/migrate-packages-config-to-package-reference


I have a strange issue, which drives me crazy…

I have a simple Class Library Project (Full .NET Framework, 4.6.1) with a wrapper class for functionality around Cosmos DB. Therefore I have added the "Microsoft.Azure.DocumentDB" NuGet Package 1.19.1 to this project. Other than that, I have a reference to the "Newtonsoft.Json" NuGet Package 10.0.3, as well as to a couple of "Microsoft.Diagnostics.EventFlow.*" NuGet Packages.

So far, everything compiles without any error.

But as soon as I hit my wrapper class – consumed from a simple Service Fabric Stateless Service (Full .NET Framework 4.6.1) – and try to execute the following line of code:

_docClient = new DocumentClient(new Uri(cosmosDbEndpointUrl), cosmosDbAuthKey);

I get this strange error at runtime:

System.IO.FileNotFoundException occurred HResult=0x80070002
Message=Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source= StackTrace: at Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel) at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel)

Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I have absolutely no clue, why the System.Net.Http assembly is not found at all – there is even a assembly reference in my class library project to the .Net Framework Assembly "System.Net.Http 4.0.0.0".

What I also do not understand is, that there is this weird binding redirect to 4.2.0.0 – where is that one coming from? To get around this one, I tried to add the following redirect to the app.config of the Service Fabric Service (which is consuming the class library):

But still no difference, I still get the error at runtime.

Anybody having a clue? Anybody having seen such issue?

Thanks and regards, OliverB

解决方案

The problem you're facing is related to Visual Studio, especially 2017 which is shipped with System.Net.Http v4.2.0.0. However, adopting the new way whereby any references should be done via NuGet, latest version of System.Net.Http which is 4.3.3 contains the dll version 4.1.1.2.

The problem is that VS at build time and at run time as well will ignore your reference and it will try to reference the DLL it knows about.

How to fix it:

  • make sure that any references to System.Net.Http are done via NuGet
  • Build time errors: change extension of System.Net.Http.dll (or move it somewhere else...basically get rid of it) that is shipped with VS 2017 (c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\); if you've got a different version then the path will slightly differ, not much though
  • Runtime errors: add an assembly binding redirect

If you look online on google you'll find a few open issues with Microsoft about this, so hopefully they'll fix this in the future.

Hope this helps.

Update:

When looking at finding some permanent fixes for this issue to work on the build agents, noticed that if you migrate to the new NuGet PackageReference model (in .csproj not in packages.config) tends to work better. Here's a link to the guide on how to do this upgrade: https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference

这篇关于找不到System.Net.Http 4.2.0.0的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆