Search code examples
azureazure-functionsazure-functions-core-tools

local development azure functions 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs'


I am having trouble running an azure function locally that works in the portal. I created a default C# Http trigger in Azure, then download the app content to run locally.

[5/22/18 9:03:21 PM] run.csx(8,23): error CS1061: 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no extension method 'GetQueryNameValuePairs' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)
[5/22/18 9:03:21 PM] run.csx(20,15): error CS1501: No overload for method 'CreateResponse' takes 2 arguments

The function works perfectly in the portal.


Solution

  • As @Mikhail has said, it's caused by the wrong functions core tools(CLI) version. The code you download works with v1 CLI(.Net Framework) while v2(you may have installed) is on .NET Core.

    To install required CLI, follow CLI installation. If local OS(like MacOS) doesn't support v1 CLI we may turn to v2 CLI which can run cross-platform. With v2 CLI, v1 code created on portal can't be used, hence we need to create functions locally or change portal function app runtime to ~2 then create and download again.

    Note that before we change the runtime, function app should be empty because functions created before depend on different runtime and usually will become invalid after the change.