繁体   English   中英

无法加载文件或程序集 System.Net.Http 4.2.0.0

[英]could not load file or assembly System.Net.Http 4.2.0.0

我真的坚持这一点,可以使用一些帮助。

当我将一个涉及 httpclient 的异步方法添加到 class 库时,这个问题就开始了。 我从一个简短的测试控制台应用程序调用 class 库。 当它到达异步方法时,我得到一个异常:

System.IO.FileNotFoundException:'无法加载文件或程序集'System.Net.Http,版本 = 4.2.0.0,文化 = 中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。 该系统找不到指定的文件。'

最初它说无法加载 System.Net.Http 版本 4.1.1.2(我在项目中有版本 4.0.0.0)并且我使用的是 Framework 4.5.2。 I could not find a system.net.http version 4.1.1.2 for NET Framework 4.5.2 so I first updated the class library and test projects to NFW 4.7.2 and then added a reference to the version of System.Net.Http associated使用此框架(即从程序集选项卡中选择它)。

当我查看 class lib 项目(toolslib)中 dll 的属性时,它显示 4.2.0.0。 我向用于调用它的测试项目添加了相同的引用,它现在也显示 4.2.0.0。

此外,我在工具库的 app.config 中添加了一个重定向部分

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a"  culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
    </dependentAssembly>

我在测试控制台应用程序的 app.config 中放置了相同的行。

但是我现在仍然遇到同样的问题,它说它无法加载 4.2.0.0。 我设置了 Fusion Logs 并在运行并获得异常后得到以下信息:

*** Assembly Binder Log Entry  (7/9/2020 @ 9:12:52 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=4.2.0.0, Culture=neutral,  ]PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Test.exe
Calling assembly : ToolsLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.2.0.0 redirected to 4.2.0.0.
LOG: Post-policy reference: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.EXE.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.EXE.
LOG: All probing URLs attempted and failed.

我从日志中唯一能看到的是它似乎试图在 test/bin/debug 文件夹中查找 dll。

我尝试将 dll 设置为复制本地但结果相同。

然后我尝试将 system.net.http dll 手动复制到 bin/debug 文件夹中,但是当我点击该方法时,我得到一个 badimage 异常,说我不能使用引用程序集。

顺便说一句,还尝试使用 nuget 更新 system.net.http,结果相同

如果我从控制台应用程序中删除 bindingredirect,问题就会消失。

不幸的是,这并不能真正解释问题,但至少现在可以解决它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM