‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’

In this azure tutorial, we will discuss how to fix the error, ‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’. This error I got after executing the Azure Function Code to interact with the Sharepoint From Azure Function using the Visual Studio 2019.

Subscribe to Our YouTube Channel for more videos

‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’

Recently, I was trying to write one Azure Function to connect to SharePoint and to delete a SharePoint list. I came across with few lines of code that are not supported with the latest version of Azure Function.

Below was my function code

using System;
using System.IO;
using System.Threading.Tasks;
//using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
//using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;
using System.Net;
using System.Net.Http;
//using Microsoft.AspNetCore.Mvc.WebApiCompatShim;
using System.Linq;

namespace deletesplistvs
{
    public static class Function1
    {
        [FunctionName("NewFunction")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage request,
            ILogger log)
        {

            string site = "https://tsinfo.sharepoint.com/sites/SPFx/";
            string userName = "bhawana@tsinfo.onmicrosoft.com";
            string password = "####@###5";

            // parse query parameter  
            string listtitle = request.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "title", true) == 0)
                .Value;


            System.Security.SecureString secureString = new System.Security.SecureString();
            foreach (char ch in password)
            {
                secureString.AppendChar(ch);
            }

When I started executing the code, I go the below error

‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’

Below is the Complete error message

Error CS1061 ‘HttpRequestMessage’ does not contain a definition for ‘GetQueryNameValuePairs’ and no accessible extension method ‘GetQueryNameValuePairs’ accepting a first argument of type ‘HttpRequestMessage’ could be found (are you missing a using directive or an assembly reference?) deletesplistvs C:\Users\Bijay\source\repos\deletesplistvs\deletesplistvs\Function1.cs 32

You can able to see the error as below

request.getquerynamevaluepairs

‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’ [Solved]

To fix the error ‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’, I am sorry to say that you have to downgrade the Azure Function version in your .csproj file.

Open your Azure Function project file i.e Projectname.csproj and do the below changes

<PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <AzureFunctionsVersion>v1</AzureFunctionsVersion>
  </PropertyGroup>

Below are the changes as highlighted

task httpresponsemessage does not contain a definition for content

Now if you will run the Project you will not get the error

Error CS1061 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no accessible extension method

But, Personally, I feel again going back to the older version of the Azure Function is not at all a good idea and looks a bit uneasy You can try using the below way

You can use the HttpRequest req as the parameter and can use it in the following way

string name = req.Query["name"];
public static class MyProductHTTPFunction
    {
        [FunctionName("MyProductHTTPFunction")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            log.LogInformation("MyProductHTTPFunction function processed a request.");

            string name = req.Query["name"];

‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePair’ – Video Tutorial

You may also like following the below articles

Wrapping Up

Well, in this article, we discussed, How to fix the error ‘HttpRequestMessage’ Does Not Contain A Definition For ‘GetQueryNameValuePairs’. Hope it will help you to fix your issue !!!