Azure / azure-functions-dotnet-worker

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

AWARENESS: OneBranch Pipelines RoslynAnalyzer task is incompatible with dotnet isolated function apps #2453

Open jviau opened 6 months ago

jviau commented 6 months ago

Description

Function app encounters runtime issues, particularly around unable to resolve services during dependency injection.

We are engaging with the OneBranch team to avoid this issue in the future. See mitigation below to address this issue now.

Who is impacted?

THIS IMPACTS INTERNAL MICROSOFT TEAMS ONLY

You are using the OneBranch pipelines RoslynAnalyzer task to build your function app

Root cause / Impact

Dotnet isolated function apps rely on source generators to emit startup hooks to configure extensions. Without these hooks extensions are in a partially configured state and will encounter runtime issues (depends on extension logic). Using OneBranch pipelines RoslynAnalyzer task to build will not run source generators, leading to these startup hooks never being ran.

When deployed you will see various DI exceptions. The exact exception you encounter depends on what extensions you see. See #2408 for an example exception.

Mitigation

To mitigate, please replace RoslynAnalyzer build task with DotNetCli task. Roslyn analyzers are included in the SDK and the OB task is not necessary for static analysis. Please follow this guide for enabling analyzers.

christianroll commented 3 months ago

How do I replace RoslynAnalyzer build task with DotNetCli task? I couldn't find a way. I'm already building with dotnet build command and still get the error from the example: https://github.com/Azure/azure-functions-dotnet-worker/issues/2408.

christianroll commented 3 months ago

@jviau this example https://github.com/Azure/azure-functions-dotnet-worker/issues/2408. is happening with dotnet 8 isolated worker with following libraries with a servicebustrigger:

`

    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.3.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.1" />`
MitchBodmer commented 2 months ago

@christianroll I came across this issue while trying to debug an issue in my own issue with a source generator and the Roslyn task. I was able to fix it by adding the loadRoslynConfiguredAnalyzersOption: Enable property to my analyzer task:

          - task: RoslynAnalyzers@3
            displayName: Run Roslyn Analyzers
            env:
              System_AccessToken: $(System.AccessToken)
            inputs:
              userProvideBuildInfo: auto
              loadRoslynConfiguredAnalyzersOption: Enable

I don't know if that will fix if for you, but it's worth a shot.

christianroll commented 2 months ago

@MitchBodmer thanks for the help, but I don't have anything similar to your case, for me it's an internal issue of azure Functions worker when I use: .ConfigureFunctionsWebApplication() for a service bus function trigger in dotnet 8 with isolated worker, if I change to .ConfigureFunctionsWorkerDefaults() this issue stops but it brings another issue for the http trigger, for more details:

https://github.com/Azure/azure-functions-dotnet-worker/issues/1947#issuecomment-2326435547

jviau commented 2 weeks ago

How do I replace RoslynAnalyzer build task with DotNetCli task? I couldn't find a way. I'm already building with dotnet build command and still get the error from the example: #2408.

You use DotNetCoreCLI@2 task instead of the roslyn analyzers task.

jviau commented 2 weeks ago

Locking this thread to avoid it being mistakenly correlated with different issues.