Azure Functions - 无法从 Azure WebJobs SDK 调用 [英] Azure Functions - can't be invoked from Azure WebJobs SDK

查看:18
本文介绍了Azure Functions - 无法从 Azure WebJobs SDK 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I've been trying to create a simple azure function, that would be an http trigger "CreateUser".
I did an other http trigger to simplify what's wrong, it looks fairly simple :

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");
        }
    }
}

这在模拟器上运行,给我带来以下错误:

This, running on the emulator, brings me the following error :

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的错误:

(My emulator's version is 5.3)
I tried to remove the parameter TraceWriter log, and the function "runs" fine... until I send it an http request using Postman, which brings an error about 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 :

I'm wondering if the attribute is the TraceWriter log that caused the previous problem and if there is a way to bring it back here...

Oh and by the way, I entered some kind of version conflicts of hell, and for some reason, had to go with .NET Standard 2.0 instead of .NET 461, which I was previously using, along the tutorial suggestion.
Here is my .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 还很陌生,我不知道发生了什么......

"Microsoft.Azure.CosmosDB.Table" is apparently not available in .NET Standard 2.0, and the .NET 461 version is restaured here, but "it's only a warning"... and "Microsoft.Azure.Storage.Common" is only on preview.

This probably have to do with a version of something somewhere, but I lost myself in tutorials that all used different stuff, and since I'm fairly new to Azure, I don't know what' happening...

推荐答案

出于某种原因,我不得不按照教程建议使用 .NET Standard 2.0 而不是我之前使用的 .NET 461.

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 function initial 时,您的函数是 .NET 461,出于某种原因,您将其更改为 .NET Standard 2.0.

It seems that when you create azure function initial, your function is .NET 461 and for some reason, you change it to .NET Standard 2.0.

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

However, when your function is .NET Standard 2.0, your runtime version should be set to beta.

所以在你的.csproj中添加AzureFunctionsVersion,因为默认的.NET 461 runtime是1,当你改成.NET core时,你需要把runtime改成手动beta".

So add AzureFunctionsVersion in your .csproj, because the default .NET 461 runtime is 1 and when you change to .NET core, you need to change the runtime to "beta" manually.

您可以参考以下代码:

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

这篇关于Azure Functions - 无法从 Azure WebJobs SDK 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆