gpt4 book ai didi

c# - Azure Functions - 无法从 Azure WebJobs SDK 调用

转载 作者:太空狗 更新时间:2023-10-30 01:13:32 24 4
gpt4 key购买 nike

所以我一直在尝试创建一个简单的 azure 函数,这将是一个http触发器“CreateUser”。
我做了另一个 http 触发器来简化问题,它看起来相当简单:

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace TutoTableAzureTemplate
{
public static class TestTrigger
{
[FunctionName("TestTrigger")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
return req.CreateResponse(HttpStatusCode.OK, "This request arrived succcesfully");
}
}
}

在模拟器上运行时,出现以下错误:

Error indexing method 'TestTrigger.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding.

(我的模拟器版本是5.3)
我尝试删除参数 TraceWriter log,并且该函数“运行”正常...直到我使用 Postman 向其发送 http 请求,这会带来有关 WebJobs 的错误:

"System.InvalidOperationException : 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes? ... "

我想知道该属性是否是导致上一个问题的 TraceWriter 日志,以及是否有办法将其带回此处...

哦,顺便说一句,我遇到了某种版本冲突的 hell ,并且出于某种原因,不得不使用 .NET Standard 2.0 而不是我之前按照教程建议使用的 .NET 461。
这是我的 .csproj :

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="9.0.0.1-preview" />
<PackageReference Include="Microsoft.Azure.CosmosDB.Table" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

“Microsoft.Azure.CosmosDB.Table” 显然在 .NET Standard 2.0 中不可用,并且 .NET 461 版本已在此处恢复,但“这只是一个警告”...并且“Microsoft.Azure.Storage.Common” 仅提供预览版。

这可能与某个地方的某个版本有关,但我迷失在所有使用不同内容的教程中,而且由于我对 Azure 相当陌生,我不知道发生了什么......

最佳答案

for some reason, had to go with .NET Standard 2.0 instead of .NET 461, which I was previously using, along the tutorial suggestion.

似乎当您初始创建azure函数时,您的函数是.NET 461,并且由于某种原因,您将其更改为.NET Standard 2.0。

但是,当您的函数是 .NET Standard 2.0 时,您的运行时版本应设置为 beta

因此,在您的.csproj中添加AzureFunctionsVersion,因为默认的.NET 461运行时为1,当您更改为.NET core时,您需要将运行时更改为手动“测试版”。

您可以引用以下代码:

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>

关于c# - Azure Functions - 无法从 Azure WebJobs SDK 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49769973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com