我真的被困在这个问题上了,需要一些帮助。
当我将一个涉及httpclient的异步方法添加到一个类库时,这个问题就开始了。我从一个简短的测试控制台应用程序调用类库。当它到达async方法时,我得到一个异常:
System.IO.FileNotFoundException:‘未能加载文件或程序集'System.Net.Http,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a’或其依赖项之一。系统找不到指定的文件。‘
最初它说无法加载System.Net.Http版本4.1.1.2 (我在项目中有版本4.0.0.0 ),而我使用的是Framework4.5.2。我找不到适用于NET Framework4.5.2的system.net.http版本4.1.1.2,所以我首先将类库和测试项目更新到NFW4.7.2,然后添加了对与此框架关联的System.Net.Http版本的引用(即从程序集选项卡中选择它)。
当我查看类库项目(toolslib)中dll的属性时,它显示4.2.0.0。我向用于调用它的测试项目添加了相同的引用,现在它也显示为4.2.0.0。
此外,我还在toolslib的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日志,并在运行并获得异常后获得了以下内容:
*** 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,结果相同
发布于 2020-07-11 06:00:57
如果我从控制台应用程序中删除bindingredirect,问题就会消失。
不幸的是,这并没有真正为这个问题提供一个解释,但它至少在目前解决了这个问题。
https://stackoverflow.com/questions/62827742
复制相似问题