简体   繁体   中英

Azure Functions : HttpRequestMessage does not contain a definition for 'CreateResponse'

I built ac# Azure functions app triggerred by an Http Request. The purpose of this app is to use digital twin to change the desired status of my device. In order to do that, I have imported the following dependencies (within the project.son file):

  "Microsoft.Azure.Devices": "1.17.2",
  "Microsoft.Azure.Devices.Client": "1.19.0",
  "Microsoft.Azure.Devices.Shared": "1.15.2",
  "Newtonsoft.Json": "12.0.1"

Here is my error, when I want to return a HttpResponseMessage

req.CreateResponse<string>(HttpStatusCode.BadRequest, "Please pass a status on the query string or in the request body");

I get the following error :

[run.csx] 'HttpRequestMessage' does not contain a definition for 'CreateResponse' and the best extension method overload 'HttpRequestMessageExtensions.CreateResponse<string>(HttpRequestMessage, HttpStatusCode, string)' requires a receiver of type 'HttpRequestMessage'

I suspect dependencies to cause this error but I haven't found any solution on internet.

Do you have an idea how to solve this ?

Thanks

Solution:

Go to kudu( https://<functionapp>.scm.azurewebsites.net/DebugConsole ) and navigate to D:\\home\\data\\Functions\\packages\\nuget , delete system.net.http package then restart the function app.

Explanation:

HttpRequestMessage locates at assembly System.Net.Http.dll . I found that Function host references the assembly from GAC(Global Assembly Cache). On Azure, file path is D:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Net.Http\\v4.0_4.0.0.0__b03f5f7f11d50a3a\\System.Net.Http.dll . The reference cannot be redirected to the one we install using nuget(packages you installed reference System.Net.Http.dll internally), or we'll get error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM