Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
432 stars 184 forks source link

ServiceBusMessageActions raises grpc exception after migrating to Isolated worker in net8.0 in servicebus trigger execution #2761

Open christianroll opened 1 month ago

christianroll commented 1 month ago

Description

Migrating to isolated worker in net8.0 using the library ServiceBusMessageActions doesn't work properly. I need to use DeadLetterMessageAsync but raises the following exception:

Exception while executing function: Functions.MessageBus_HandleSplashContractedCampaigns Result: Failure
Exception: System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Azure.ServiceBus.Grpc.Settlement+SettlementClient' while attempting to activate 'Microsoft.Azure.Functions.Worker.ServiceBusMessageActionsConverter'.

My fsproj is as below using all latest version:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0-preview1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0-preview2" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.22.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.4.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-rc.1.24431.7" />
        <PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0-rc.1.24431.7" />
        <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.1" />
    </ItemGroup>
....

Migrating without usage of ServiceBusMessageActions is totally fine, the servicebus trigger works but has this limitation of not being able to use deadLetterMessageAsync...

I referenced this in this thread as well: https://github.com/Azure/azure-functions-dotnet-worker/issues/2102#issuecomment-2401618521

Steps to reproduce

Having a servicebus trigger in isolated worker in dotnet 8.0 referecing library ServiceBusMessageActions when it gets triggered it will raise grpc exception mentioned previously.

jviau commented 1 week ago

@christianroll I see you are using preview packages. We recently release GA 2.0.0, can you try those? Additionally, can you verify source gen is running for your project? Source gen is crucial in emitting code which will hook up extension configuration calls. Without those calls service bus will not register its services and lead to issues like this.

christianroll commented 1 week ago

@jviau I upgraded all the versions to latest 2.0.0 and I also forced to be false: <FunctionsEnableExecutorSourceGen>false</FunctionsEnableExecutorSourceGen> but no success, still getting this error:

Exception: Unable to resolve service for type 'Microsoft.Azure.ServiceBus.Grpc.Settlement+SettlementClient' while attempting to activate 'Microsoft.Azure.Functions.Worker.ServiceBusMessageActionsConverter'.

jviau commented 3 days ago

@christianroll FunctionsEnableExecutorSourceGen property should be unrelated to the source gen I am talking about. Can you see this comment and let me know if you see the GeneratedFunctionMetadataProvider.g.cs being generated?