C# 将.NET Core 3.1迁移到.NET 5.0,AzureFunctions,无法转换输入参数';需求';输入';System.Net.Http.HttpRequestMessage'; 我正在从.NET核心3.1迁移到我的Azure函数项目的.NET 5。我有以下功能去宽容: 使用Microsoft.Azure.Functions.Worker; 使用Microsoft.Azure.Functions.Worker.Http; 使用Microsoft.Extensions.Logging; 使用制度; 使用System.Collections.Generic; 使用System.IO; 使用System.Linq; 使用System.Net.Http; [功能(“测试”)] 公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequestMessage请求, 伊洛格日志, Microsoft.Azure.WebJobs.ExecutionContext(上下文) { ... }
但是,我收到以下错误消息:C# 将.NET Core 3.1迁移到.NET 5.0,AzureFunctions,无法转换输入参数';需求';输入';System.Net.Http.HttpRequestMessage'; 我正在从.NET核心3.1迁移到我的Azure函数项目的.NET 5。我有以下功能去宽容: 使用Microsoft.Azure.Functions.Worker; 使用Microsoft.Azure.Functions.Worker.Http; 使用Microsoft.Extensions.Logging; 使用制度; 使用System.Collections.Generic; 使用System.IO; 使用System.Linq; 使用System.Net.Http; [功能(“测试”)] 公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequestMessage请求, 伊洛格日志, Microsoft.Azure.WebJobs.ExecutionContext(上下文) { ... },c#,.net,azure-functions,.net-5,.net-core-3.1,C#,.net,Azure Functions,.net 5,.net Core 3.1,但是,我收到以下错误消息: System.Private.CoreLib: Exception while executing function: Functions.SaveBlob. System.Private.CoreLib: Result: Failure Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting
System.Private.CoreLib: Exception while executing function: Functions.SaveBlob. System.Private.CoreLib: Result: Failure
Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters for Function 'Test': Cannot convert input parameter 'req' to type 'System.Net.Http.HttpRequestMessage' from type 'Microsoft.Azure.Functions.Worker.GrpcHttpRequestData'.
我需要为我的应用程序保留ExecutionContext
如何修复此错误?阅读后,我看到该类已重命名为
解决这个问题的方法很简单,将ExecutionContext
重命名为FunctionContext
。我意识到.NET 5 Azure功能不需要Microsoft.Azure.WebJobs。接下来,我需要将类型从System.Net.Http.HttpRequestMessage
更改为Microsoft.Azure.Functions.Worker.Http.HttpRequestData
。最后,我删除了ILogger
,以支持
最后一个函数如下所示
使用系统;
使用System.IO;
使用System.Threading.Tasks;
使用Microsoft.Azure.Functions.Worker;
使用Microsoft.Azure.Functions.Worker.Http;
[功能(“测试”)]
公共静态HttpResponseData运行([HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequestData请求
函数(上下文)
{
...
}
升级时,请确保彻底升级。它还帮助通过VisualStudio代码创建一个新项目,使用.NET5查看新项目的结构