4

I'm making a NuGet package and my csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
    ...
    <PackageId>Package2</PackageId>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Package1\Package1.csproj" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
    <Reference Include="System.Net.Http" />
  </ItemGroup>

</Project>

The project it's referencing looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
    <PackageId>Package1</PackageId>
    ...
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <NoWarn>1701;1702; CS1591</NoWarn>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461'">
      <PackageReference Include="System.ValueTuple" Version="4.5.0" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
    <Reference Include="System.Net.Http" />
  </ItemGroup>

</Project>

And inside the Package2 project it has the following line:

webRequestHandler.ClientCertificates.Add(certificate);

But it isn't building in net461 or net47, saying:

'HttpClientHandler' does not contain a definition for 
'ClientCertificates' and no accessible extension method 
'ClientCertificates' accepting a first argument of type
'HttpClientHandler' could be found (are you missing a using
 directive or an assembly reference?) 

Package2(net461),
Package2(net47)

But the only thing I've changed is removed this from the csproj for package2:

  <ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
  </ItemGroup>

Can anyone help me understand how to fix it? I don't really want to bring in that whole NuGet package just to fix this one dependency I think I'm just missing an assembly but as far as I know it should be in System.Net.Http which I should already be referencing (and so should the other project it's already dependent on).

Jamie Twells
  • 1,924
  • 4
  • 26
  • 56

3 Answers3

4

Looks like this property is available from version 4.7.1:

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.clientcertificates?view=netframework-4.7.1

Note that if you select an older .NET version, you'll see a message like this:

The requested page is not available for .NET Framework 4.7.
Desarc
  • 121
  • 5
4

For me the solution was to download the newest version of "System.Net.Http". You can find it through the NuGet package manager.

At the time of writing v4.3.4 is the newest version and it contains the ClientCertificates methode.

0

I've swapped out the assembly reference for the NuGet package:

  <ItemGroup Condition="'$(TargetFramework)'=='net47' OR '$(TargetFramework)'=='net461'">
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
  </ItemGroup>

pretty sure this is the wrong thing to do™ as the assembly reference in .NET Framework should be sufficient and I'm probably going to suffer many conflicting reference issues anywhere I install my package, but this is the best I can come up with right now.

Jamie Twells
  • 1,924
  • 4
  • 26
  • 56