Azure Functions - can't be invoked from Azure WebJobs SDK
Asked Answered
O

4

10

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

Ombudsman answered 11/4, 2018 at 8:18 Comment(3)
Could you add your runtime version: run func command and copy lines like Azure Functions Core Tools (xyz) and Function Runtime Version: xyz.Mourant
Can this help? I had the exact same problem with Functions running .netstandard 2.0: #49672511Wongawonga
This is what i got : Azure Functions Core Tools (1.0.10) and Function Runtime Version: 1.0.11612.0... And here I run on the emulator only, but I'll watch out for beta's runtime thing when I'll publish it to Azure's Cloud thoughOmbudsman
R
7

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>
Remaremain answered 12/4, 2018 at 7:47 Comment(3)
Yeah, it actually makes sense, and it fixed this binding error... Also I stopped using CosmosDB package, to use the one that is already part of Sdk functions, WindowsStorage.Table, which is supported in Standard.Ombudsman
Thank you for your answer and may I know how can I change the runtime version to beta?Lockwood
By default, function apps created in the Azure portal are set to version 2.x. You can only change the runtime version after you create your function app but before you add any functions. Here is the article. And go to your function app>function app settings >Runtime version you will find it.Remaremain
L
8

I just had the same 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?"-error in a v4 function running .Net 6.0.

In my case it was as simple as a bad route, like this:

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

Should have been like this:

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

Note this part: Route = BaseUrl + "/{fileId}".

Super easy fix, but the annoying part was that it didn't hit any breakpoints, making it a bit difficult for me to pinpoint.

Lowenstern answered 28/2, 2022 at 13:9 Comment(0)
R
7

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>
Remaremain answered 12/4, 2018 at 7:47 Comment(3)
Yeah, it actually makes sense, and it fixed this binding error... Also I stopped using CosmosDB package, to use the one that is already part of Sdk functions, WindowsStorage.Table, which is supported in Standard.Ombudsman
Thank you for your answer and may I know how can I change the runtime version to beta?Lockwood
By default, function apps created in the Azure portal are set to version 2.x. You can only change the runtime version after you create your function app but before you add any functions. Here is the article. And go to your function app>function app settings >Runtime version you will find it.Remaremain
F
0

I encountered this issue when creating a new Azure Function V2 on VS 2019 and I included another project that the function app is referencing to. Removing the other project fixed it for me.

Forestaysail answered 29/1, 2020 at 16:36 Comment(3)
is there any work around? i need multiple projects to be referenced. thanksGlandular
Try upgrading your function into v3 or package the other project your dependent into nuget.Forestaysail
@Glandular another way that I resolved this is through dependency injection. I was able to reference another projects using it.Forestaysail
I
0

It's 2020 and I created my Azure Functions v1 in vs 2019 and got the same error. I however figured out a work around by editing the .csproj file as follows:

    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
Interflow answered 23/6, 2020 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.