Azure Functions - 无法从 Azure WebJobs SDK 调用
Azure Functions - can't be invoked from Azure WebJobs SDK
所以我一直在尝试创建一个简单的 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
,函数 "runs" 很好......直到我使用 Postman 向它发送一个 http 请求,这带来了关于 WebJobs 的错误:
"System.InvalidOperationException : 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes? ... "
我想知道该属性是否是导致先前问题的 TraceWriter log
,是否有办法将其恢复到此处...
哦,顺便说一句,我遇到了地狱般的版本冲突,出于某种原因,我不得不使用 .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 版本,但是 "it's only a warning"... 和 "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时,你需要改变运行时手动设置为“beta”。
您可以参考以下代码:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
我在 VS 2019 上创建新的 Azure Function V2 时遇到了这个问题,我包含了函数应用程序引用的另一个项目。删除其他项目为我修复了它。
现在是 2020 年,我在 vs 2019 中创建了我的 Azure Functions v1,但遇到了同样的错误。然而,我通过如下编辑 .csproj 文件找到了解决方法:
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
我刚刚在 v4
函数 运行 .Net 6.0
.
中遇到了同样的 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?"
-错误
在我的例子中,它就像一条糟糕的路线一样简单,就像这样:
public async Task<Models.BinaryFile> GetAsync([HttpTrigger(AuthorizationLevel.Function, "get",
Route = BaseUrl)] HttpRequest req, Guid fileId, ILogger log)
{
// [logic to get file here...]
return file;
}
本来应该是这样的:
public async Task<Models.BinaryFile> GetAsync([HttpTrigger(AuthorizationLevel.Function, "get",
Route = BaseUrl + "/{fileId}")] HttpRequest req, Guid fileId, ILogger log)
{
// [logic to get file here...]
return file;
}
注意这部分:Route = BaseUrl + "/{fileId}"
。
超级简单的修复,但令人讨厌的是它没有遇到任何断点,这让我很难确定。
所以我一直在尝试创建一个简单的 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
,函数 "runs" 很好......直到我使用 Postman 向它发送一个 http 请求,这带来了关于 WebJobs 的错误:
"System.InvalidOperationException : 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes? ... "
我想知道该属性是否是导致先前问题的 TraceWriter log
,是否有办法将其恢复到此处...
哦,顺便说一句,我遇到了地狱般的版本冲突,出于某种原因,我不得不使用 .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 版本,但是 "it's only a warning"... 和 "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时,你需要改变运行时手动设置为“beta”。
您可以参考以下代码:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
我在 VS 2019 上创建新的 Azure Function V2 时遇到了这个问题,我包含了函数应用程序引用的另一个项目。删除其他项目为我修复了它。
现在是 2020 年,我在 vs 2019 中创建了我的 Azure Functions v1,但遇到了同样的错误。然而,我通过如下编辑 .csproj 文件找到了解决方法:
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
我刚刚在 v4
函数 运行 .Net 6.0
.
'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?"
-错误
在我的例子中,它就像一条糟糕的路线一样简单,就像这样:
public async Task<Models.BinaryFile> GetAsync([HttpTrigger(AuthorizationLevel.Function, "get",
Route = BaseUrl)] HttpRequest req, Guid fileId, ILogger log)
{
// [logic to get file here...]
return file;
}
本来应该是这样的:
public async Task<Models.BinaryFile> GetAsync([HttpTrigger(AuthorizationLevel.Function, "get",
Route = BaseUrl + "/{fileId}")] HttpRequest req, Guid fileId, ILogger log)
{
// [logic to get file here...]
return file;
}
注意这部分:Route = BaseUrl + "/{fileId}"
。
超级简单的修复,但令人讨厌的是它没有遇到任何断点,这让我很难确定。