2

Following an online guide for building a C# class, and pasting the class code into a new class, the only part that doesn't resolve is this line:

        canonicalRequest.AppendFormat("{0}\n", GetCanonicalQueryParameters(request.RequestUri.ParseQueryString()));

From this function

    private static string GetCanonicalRequest(HttpRequestMessage request, string[] signedHeaders)
    {
        var canonicalRequest = new StringBuilder();
        canonicalRequest.AppendFormat("{0}\n", request.Method.Method);
        canonicalRequest.AppendFormat("{0}\n", request.RequestUri.AbsolutePath);
        canonicalRequest.AppendFormat("{0}\n", GetCanonicalQueryParameters(request.RequestUri.ParseQueryString()));
        canonicalRequest.AppendFormat("{0}\n", GetCanonicalHeaders(request, signedHeaders));
        canonicalRequest.AppendFormat("{0}\n", String.Join(";", signedHeaders));
        canonicalRequest.Append(GetPayloadHash(request));
        return canonicalRequest.ToString();
    }

The error is that System.Uri doesn't contain a definition for parsequerystring? This seems odd, as MSDN reveals this is a legitimate function that is used to get the query part of a URL. I have all the required usings and references, but this still won't resolve. Any ideas?

JamesMatson
  • 2,522
  • 2
  • 37
  • 86

1 Answers1

4

You need to add a reference to the System.Net.Http.Formatting library (right click on References, then select "Add Reference", browse the .NET references for that library.

Then be sure to add the correct "using" at the top:

using System.Net.Http

The method is an extension method, and the documentation can be found here on MSDN.

Ron Beyer
  • 11,003
  • 1
  • 19
  • 37
  • All I can find is System.Net.Http and System.Net.Http.WebRequest (and I have added references via that method before, so I'm sure I'm doing the right thing, but it's just not there :/ I'm using Framework 4.5.2 by the way.... – JamesMatson Mar 02 '18 at 09:12
  • Solved - needed to use Nuget, and a VERY specific version of the assembly, any other version produces a failed constraint against another assembly, but this one works OK PM> Install-Package System.Net.Http.Formatting -Version 4.0.20505 – JamesMatson Mar 02 '18 at 22:57