In this article I will explain with an example, how to resolve the following error while using classes that requires System.Net.Http namespace to be inherited.
CS0246: The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)
Error
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)
Cause
This error occurs because the required namespace is not inherited or the System.Net.Http reference is not added.
There are many Classes, Structs, Interfaces and Enums that requires the System.Net.Http namespace that you need to inherit.
HttpClient is one of that class that requires.
Solution
In order to get rid of this error, you need to add the reference of System.Net.Http.
Adding Reference
1. Expand your project and right click on Bin folder and click on Add Reference.
2. Inside the Reference Manager window, inside the Left Pane expand Assemblies and then select Extensions and then look for System.Net.Http, select it and click OK.