我构建了一个由 Http 请求触发的 C# Azure 函数应用程序。该应用程序的目的是使用数字孪生来更改我的设备的所需状态。为此,我导入了以下依赖项(在 project.son 文件中):
"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"
当我想返回 HttpResponseMessage 时,这是我的错误
req.CreateResponse<string>(HttpStatusCode.BadRequest, "Please pass a status on the query string or in the request body");
我收到以下错误:
[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'
我怀疑依赖项导致了此错误,但我在互联网上没有找到任何解决方案。
你知道如何解决这个问题吗?
谢谢
最佳答案
解决方案:
转到 kudu( https://<functionapp>.scm.azurewebsites.net/DebugConsole
) 并导航到 D:\home\data\Functions\packages\nuget
,删除system.net.http
打包然后重新启动函数应用程序。
说明:
HttpRequestMessage
位于装配System.Net.Http.dll
。我发现Function主机引用了GAC(全局程序集缓存)中的程序集。在 Azure 上,文件路径为 D:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll
。该引用无法重定向到我们使用 nuget 安装的引用(您安装的包在内部引用 System.Net.Http.dll
),否则我们会收到错误。
关于c# - Azure函数: HttpRequestMessage does not contain a definition for 'CreateResponse' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54377126/