6

I am trying to use HttpClient client however I am unable to use using System.Net.Http;. How to correctly use C# libraries in JetBrains Rider?

enter image description here

The os is linux.

Greg
  • 8,175
  • 16
  • 72
  • 125
  • 1
    Google "jetbrains rider add reference" > "For now there are only one way to edit them - editing *.csproj file." – Camilo Terevinto May 22 '18 at 00:40
  • 1
    @CamiloTerevinto This is no longer accurate with current releases of Rider. – Jonathon Chase May 22 '18 at 01:12
  • 2
    as a little side note, using doesn't import a library. It's purely a namespace thing. It's like saying "everything in this namespace I want to use as if it was in the global namespace". It means you don't need to fully qualify everything. – Keith Nicholas May 22 '18 at 01:19

1 Answers1

5

System.Net.Http is not a standard reference included with console applications. You will need to add the reference explicitly to use it.

You can do this in Rider by right clicking the project in question, selecting Add > Add Reference. This will pop a dialog that will populate the system references. Once populated, find System.Net.Http and select it. Confirm the dialog. Your using should now work as expected.

Tested with Rider 2018.1 on windows.

Jonathon Chase
  • 9,396
  • 21
  • 39
  • 2
    What if it doesn't? Where are those System libraries actually located? My rider populates this dialog with my project's internals – Konstantin Oct 18 '18 at 16:29
  • 2
    @Konstantin If you can't reference it as a system library, I would recommend you add the `System.Net.Http` NuGet package instead of attempting to path to it directly, as that is likely to break the project in other people's environments. – Jonathon Chase Oct 18 '18 at 16:38
  • Thanks! I'll try that – Konstantin Oct 18 '18 at 16:40