Azure / azure-functions-dotnet-worker

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

.NET 8 Isolated function do not startup on Azure environment #2535

Closed igor-henriques closed 2 months ago

igor-henriques commented 3 months ago

Description

I'm using an Azure Function .NET 8 Isolated (upgraded from .NET 6 template) and also using the official AzureFunctionApp@2 pipeline deploy task to handle the deployment. Locally everything runs fine without any issue, but when deployed I'm seeing this error:

Microsoft.Azure.WebJobs.Script.ExternalStartupException : Error configuring services in an external startup class. ---> System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.AspNetCore.Routing, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified

This is my deploy stage:

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()

  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: 'development'
    pool:
      name: 'SelfHostedAgentPool'
      vmImage: 'ubuntu-latest'

    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureFunctionApp@2
            displayName: 'Azure functions app deploy'
            inputs:
              azureSubscription: '$(azureSubscription)'
              appType: functionApp
              appName: $(functionAppName)
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

The thing is, I don't even have that .dll in my output folder, although I have the package as a dependency from Microsoft.Azure.WebJobs.Extensions.Http (3.2.0), which in turn is a dependency of Microsoft.NET.Sdk.Functions (4.0.0).

image

and guess what, I can't downgrade to a non-deprecated version (what?!) because it is a dependency of a major package, and I can't also see that dll in my output folder as well.

Plus: the template offered by VS (2022) didn't even include the package that is causing the issue here on this topic: Microsoft.Azure.Functions.Worker.Extensions.ServiceBus

All packages I have now are:

<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.5" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Polly" Version="8.4.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="Twilio" Version="7.1.1" />

So, indeed, the root cause here, at least for me, is Microsoft.NET.Sdk.Functions, which I can't just downgrade because all non-deprecated versions still has that same dependency chain that end up needing the same Microsoft.AspNetCore.Routing, Version=7.0.0 package

This issue might be related to https://github.com/Azure/azure-functions-dotnet-worker/issues/2270, but, as apparently no one gave the required attention to that one, I'm also raising this.

THIS IS AN ISSUE!!

Steps to reproduce

  1. Create a .NET 6 Isolated azure function template triggered by Service Bus
  2. Upgrade the version to .NET 8
  3. Upgrade the packages
  4. Deploy (I haven't tested with a publish profile, only pipeline)
  5. See the error
igor-henriques commented 3 months ago

UPDATE:

It was weird to me that I couldn't see any .NET 8 template, so I searched a little bit and found out that on VS Tools > Options > Projects and Solutions > Azure Functions I could update my az func tools and templates included.

After that, I could see the template for .NET 8 and it changes a lot from the .NET 6. So I created a separated project and copied all the csproj property group tag, packages and startup class to my project, deployed, boom, same issue again. Then I decided to MOVE all my implementations to the brand new project, deleted my own project from my solution and then imported the brand new .NET 8 template with my code moved back to my solution and it worked. Now I'm having a different issue.

From AI logs:

0 functions loaded
1 functions found (Custom)

Based on some searches, it might be ArchiveFiles@2 pipeline step faults, but I already tried to deploy with all possible parameter combinations and still the same error. There are tho some difference when I switch includeRootFolder to false.

With it set to true, this is what I see on App files tab:

image

When it is set to false, there is this raw text:

[{"name":"MyPackage.Functions.PackageNotification.zip","size":8516189,"mtime":"2024-06-14T04:34:08+00:00","crtime":"2024-06-14T04:34:08+00:00","mime":"application/x-zip-compressed","href":"https://mypackage-dev.azurewebsites.net/admin/vfs/publish_output/MyPackage.Functions.PackageNotification.zip?relativePath=1&api-version=2022-03-01","path":"C:\\home\\site\\wwwroot\\publish_output\\MyPackage.Functions.PackageNotification.zip"}]

At this point the only approach left for me is to abaddon my pipeline and try to deploy through publish profiles.

igor-henriques commented 3 months ago

UPDATE:

It was weird to me that I couldn't see any .NET 8 template, so I searched a little bit and found out that on VS Tools > Options > Projects and Solutions > Azure Functions I could update my az func tools and templates included.

After that, I could see the template for .NET 8 and it changes a lot from the .NET 6. So I created a separated project and copied all the csproj property group tag, packages and startup class to my project, deployed, boom, same issue again. Then I decided to MOVE all my implementations to the brand new project, deleted my own project from my solution and then imported the brand new .NET 8 template with my code moved back to my solution and it worked. Now I'm having a different issue.

From AI logs:

0 functions loaded
1 functions found (Custom)

Based on some searches, it might be ArchiveFiles@2 pipeline step faults, but I already tried to deploy with all possible parameter combinations and still the same error. There are tho some difference when I switch includeRootFolder to false.

With it set to true, this is what I see on App files tab:

image

When it is set to false, there is this raw text:

[{"name":"MyPackage.Functions.PackageNotification.zip","size":8516189,"mtime":"2024-06-14T04:34:08+00:00","crtime":"2024-06-14T04:34:08+00:00","mime":"application/x-zip-compressed","href":"https://mypackage-dev.azurewebsites.net/admin/vfs/publish_output/MyPackage.Functions.PackageNotification.zip?relativePath=1&api-version=2022-03-01","path":"C:\home\site\wwwroot\publish_output\MyPackage.Functions.PackageNotification.zip"}]

At this point the only approach left for me is to abaddon my pipeline and try to deploy through publish profiles.

Publish profiles is working. Just tested. Very likely the issue is related to one of the pipeline steps, either the zipping or the deploying.

kshyju commented 3 months ago

"Microsoft.NET.Sdk.Functions

An isolated function does not need this package. That package was meant to be used by in-process applications. Why do you still have this package reference in your dotnet isolated function app?

and startup class to my project,

What startup class are you referring to? Keep in mind that the startup class you use in the ni-proc model will not work for isolated model.

Publish profiles is working. Just tested. Very likely the issue is related to one of the pipeline steps, either the zipping or the deploying.

Let us know what you find.

microsoft-github-policy-service[bot] commented 2 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

If you are not the original author (igor-henriques) and believe this issue is not stale, please comment with /bot not-stale and I will not close it.

microsoft-github-policy-service[bot] commented 2 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.