Could not load file or assembly 'System.Net.Ht

2019-06-25 09:22发布

问题:

I don't know what I did, but I may have removed System.Net.Http 4.0.0.0 from the GAC. I have a Windows Portable Library that targets WinRT that was compiling and working fine, and now I get the following error every time I try and run it

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.":"System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

how can I re-add System.Net.Http 4.0.0.0? Every time I look for the .dll, I find the 2.0.0.0 version?

回答1:

To repair this on versions of Windows prior to Windows 8, go to Add or Remove Programs and do a repair install of the .NET Framework 4.5.

To pair this on versions Windows 8 or greater, you will need to run System Restore to restore Windows binaries to an earlier version when it did work.



回答2:

Have you tried to delete, then re-add the reference from the project?



回答3:

Try folder:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0
and copy the dll into GAC using gacutil tool from folder
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin



回答4:

If it was but now is not, is high likely that you changed something in your project, if i understand correctly you're creating a Portable Library (not a Windows Store one), if that's the case, probably you changed what plataforms you're targeting, open the Properties of the project and in Library->Target Frameworks click on Change, there, if you have everything selected or .NET Framework 4.0.3 is selected, then System.Net.Http is not allowed, to solve this, you need to quit some selections and enable the .NET Framework 4.5, as this the minimum version to use System.Net.Http.