Dan Van
Dan Van

Reputation: 85

.Net 7 Azure function for isolated process compile error with ServiceBusTrigger

I'm adding a new azure function (isolated process) to a running .net 7 project, but got the compile error "The attribute 'ServiceBusTrigger' is a WebJobs attribute and not supported in the .NET Worker (isolated process)".

We're using isolated process for .net 7 at the moment and it can't be changed.

Even the simple function generated by chatGPT also can't be built because of that error

[Function("MyServiceBusTriggerFunction")] public static void Run( [ServiceBusTrigger("", "")] ServiceBusReceivedMessage message, FunctionContext context) { }

Any help will be much appreciated.

Upvotes: 3

Views: 1156

Answers (1)

Ikhtesam Afrin
Ikhtesam Afrin

Reputation: 6497

I have reproduced the issue at my environment using .Net 7 isolated process with service Bus triggered function and got the expected result

The attribute 'ServiceBusTrigger' is a WebJobs attribute and not supported in the .NET Worker (isolated process)

Please check if you have below items in your .csproj file. You can refer to this SO Thread for more details about the error.

<ItemGroup>

<PackageReference  Include="Microsoft.Azure.Functions.Worker"  Version="1.10.0"  />
<PackageReference  Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus"  Version="4.2.1"  />
<PackageReference  Include="Microsoft.Azure.Functions.Worker.Sdk"  Version="1.7.0"  />

</ItemGroup>

I have created a default service Bus queue triggered function using VS code.

I have below files created in vs code

enter image description here

Code:

using  System;
using  Microsoft.Azure.Functions.Worker;
using  Microsoft.Extensions.Logging;

namespace  Company.Function
{

public  class  ServiceBusQueueTrigger1
{
private  readonly  ILogger  _logger;
public  ServiceBusQueueTrigger1(ILoggerFactory  loggerFactory)
{
_logger  =  loggerFactory.CreateLogger<ServiceBusQueueTrigger1>();
}
[Function("ServiceBusQueueTrigger1")]
public  void  Run([ServiceBusTrigger("myqueue", Connection  =  "afreen001_SERVICEBUS")] string  myQueueItem)
{
_logger.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
}
}

local.settings.json:

{

"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"afreen001_SERVICEBUS": "*****************"

}
}

Output:

enter image description here

Upvotes: 4

Related Questions