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

查看:185
本文介绍了Azure函数-无法从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,并且功能运行"正常……直到我使用邮递员向其发送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函数时,您的函数是.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运行时为1 ,并且当您更改为.NET Core时,需要将运行时更改为" 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函数-无法从Azure WebJobs SDK调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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