Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions - can't be invoked from Azure WebJobs SDK

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.

(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? ... "

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" 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...

like image 472
Pierre Lartigau Avatar asked Apr 11 '18 08:04

Pierre Lartigau


People also ask

What is the difference between Azure Functions and WebJobs?

Summary. Azure Functions offers more developer productivity than Azure App Service WebJobs does. It also offers more options for programming languages, development environments, Azure service integration, and pricing. For most scenarios, it's the best choice.

What is Azure WebJobs SDK?

The Azure WebJobs SDK is a framework that simplifies the task of writing background processing code that runs in Azure WebJobs. It includes a declarative binding and trigger system that works with Azure Storage Blobs, Queues and Tables as well as Service Bus.

Which of the following is not true about WebJobs?

Explanation : A. Incorrect: WebJobs can be triggered by both queue messages and blobs.


Video Answer


1 Answers

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

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.

However, when your function is .NET Standard 2.0, your runtime version should be set to 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.

You could refer to the following code:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
like image 138
Joey Cai Avatar answered Sep 26 '22 01:09

Joey Cai