c# version=22.214.171.124 - Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified
Whenever I have a NuGet error such as these I usually take these steps:
- Go to the packages folder in the Windows Explorer and delete it.
- Open Visual Studio and Go to Tools > Library Package Manager > Package Manager Settings and under the Package Manager item on the left hand side there is a "Clear Package Cache" button. Click this button and make sure that the check box for "Allow NuGet to download missing packages during build" is checked.
- Clean the solution
- Then right click the solution in the Solution Explorer and enable NuGet Package Restore
- Build the solution
Taking all of these steps almost always restores all the packages and dll's I need for my MVC program.
For Visual Studio 2013 and above, step 2) should read:
- Open Visual Studio and go to Tools > Options > NuGet Package Manager and on the right hand side there is a "Clear Package Cache button". Click this button and make sure that the check boxes for "Allow NuGet to download missing packages" and "Automatically check for missing packages during build in Visual Studio" are checked.
I have a small MVC app that I use for practice reasons, but now I am encountering an error every time I try to debug:
Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified.
I've googled but cannot find a solution. I'm using .NET 4.5.
It can't be the DLL file because I'm using .Net 4.5.
I found an extra
<dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-126.96.36.199" newVersion="188.8.131.52" /> </dependentAssembly>
in my web.config. removed that to get it to work. some other package I installed, and then removed caused the issue.
user3919888 pointed me in the right direction, but I needed to run
Update-Package -reinstall Microsoft.AspNet.WebApi.Client in the Package-Manager console. Basic install by itself does not recognize the problem but does recognize that the package is already installed and does not overwrite it.
I'm posting this answer because this happens so infrequently that I end up googling and reaching this page before I remember what I did last time.
- Remove all code references to System.Net.*
- Uninstall:Package Microsoft.AspNet.WebApi and its dependent.
- Reinstall all : Package Microsoft.AspNet.WebApi and its dependent.
- Clean and rebuild your project
For me it was as simple as
Microsoft.AspNet.WebApi.Clientfrom the packages folder in Windows Explorer
- Open Tools > NuGet Package Manager > Package Manager Console
- Click the "Restore" button
Probably you need to set library reference as "Copy Local = True" on properties dialog. On visual studio click on "references" then right-click on the missing reference, from the context menu click properties, you should see copy local setting.
For Me adding few below line in WebApi.config works as after updating the new nuget package did not works out
var setting = config.Formatters.JsonFormatter.SerializerSettings; setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); setting.Formatting = Formatting.Indented;
Don't forget to add namespace:
using Newtonsoft.Json.Serialization; using Newtonsoft.Json;