azure-functions-dotnet-worker: Azure function startup failure "Could not load file or assembly" after upgrading to latest version

After upgrading the packages:

  • Microsoft.Azure.Functions.Worker.Sdk from 1.14.1 to 1.15.1
  • Microsoft.Azure.Functions.Worker.Extensions.ServiceBus from 5.13.0 to 5.14.1

My Azure function fails to start up, the error is: image

Error configuring services in an external startup class. 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.

Microsoft.Azure.WebJobs.Script.ExternalStartupException:
System.IO.FileNotFoundException:
   at Microsoft.Extensions.DependencyInjection.GrpcServicesExtensions.AddGrpc (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad)
   at Microsoft.Azure.WebJobs.Extensions.Rpc.WebJobsExtensionBuilderRpcExtensions.AddCoreServices (Microsoft.Azure.WebJobs.Extensions.Rpc, Version=3.0.37.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Extensions.Rpc\WebJobsExtensionBuilderRpcExtensions.cs:39)
   at Microsoft.Azure.WebJobs.Extensions.Rpc.WebJobsExtensionBuilderRpcExtensions.MapWorkerGrpcService (Microsoft.Azure.WebJobs.Extensions.Rpc, Version=3.0.37.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Extensions.Rpc\WebJobsExtensionBuilderRpcExtensions.cs:31)
   at Microsoft.Extensions.Hosting.ServiceBusHostBuilderExtensions.AddServiceBus (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.13.3.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Microsoft.Extensions.Hosting.ServiceBusHostBuilderExtensions.AddServiceBus (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.13.3.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Microsoft.Azure.WebJobs.ServiceBus.ServiceBusWebJobsStartup.Configure (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.13.3.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureStartup (Microsoft.Azure.WebJobs.Host, Version=3.0.39.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:166)
   at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureAndLogUserConfiguredServices (Microsoft.Azure.WebJobs.Host, Version=3.0.39.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:130)
   at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseWebJobsStartup (Microsoft.Azure.WebJobs.Host, Version=3.0.39.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:115)
   at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseExternalStartup (Microsoft.Azure.WebJobs.Host, Version=3.0.39.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:213)
   at Microsoft.Azure.WebJobs.Script.ScriptHostBuilderExtensions+<>c__DisplayClass7_0.<AddScriptHostCore>b__1 (Microsoft.Azure.WebJobs.Script, Version=4.27.0.0, Culture=neutral, PublicKeyToken=null: /src/azure-functions-host/src/WebJobs.Script/ScriptHostBuilderExtensions.cs:226)

Downgrading Worker.Sdk back to 1.14.1 and Worker.Extensions.ServiceBus back to 5.13.0 fixed the issue. This is a similar experience to what was reported in #1950, but different packages.

The complete list of packages used in my project is:

<PackageReference Include="Azure.Identity" Version="1.10.3" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.18.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.14.1" />
<PackageReference Include="CommandQuery.DependencyInjection" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="7.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="6.1.1" />

Let me know if you need more information.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 15
  • Comments: 82 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I believe I have gotten to the root of this issue thanks to help from @Krumelur . The issue is VS publish, it is passing an explicit TargetFramework=net8.0 argument to the publish, which overrides the inner project TFM of net6.0, which causes the net7.0 copy of Grpc.AspNetCore.Server to be included and thus the load issues.

Mitigation: In Visual Studio solution explorer, open your publish profile (ie: Properties/PublishProfiles/{appName} - Zip Deploy.pubxml). Delete the line that contains <TargetFramework>net8.0</TargetFramework> then publish. NOTE: Visual Studio will re-add this property next time you edit and save publish settings (below). If Target Framework is listed in the below area, then you will need to perform the delete again.

image

Fix: I will fix this properly in our SDK, we need expand on the set of global properties to ignore when invoking the inner build. TFM is one of them.

Just sharing a “me too” for both this issue on .NET 8 as well as the functional work-around with removing the .NET 8 line from the publish profile for right-click deploys in Visual Studio 2022. (Now I’m going to go kick a brick about the fact that I’m even doing right-click deploys right now.)

We’re using 5.15.0 & 1.16.4 of those two packages (newest stable versions on nuget).

Hi everyone,

I encountered the same issue described in this thread after updating two very similar Azure Functions event listeners from .NET 6 to .NET 8 and moving to the isolated worker model. Interestingly, only the second listener encountered the

Error configuring services in an external startup class. Grpc.AspNetCore.Server: Could not load file or assembly ‘Microsoft.AspNetCore.Routing, Version=7.0.0.0 …’ The system cannot find the file specified.

error, while the first one updated without issues. Maybe this suggests that the problem could depend on subtle differences in project configuration or dependencies.

For the listener that encountered errors, I managed to fix this locally by deleting the ‘bin’ and ‘obj’ directories from my local project folder. After rebuilding the project and running the function locally, it worked without issues. To anyone experiencing this issue, I suggest trying these steps to see if it resolves the problem in your local development environment. I haven’t yet tested this solution in a deployed Azure environment, so I can’t confirm if it resolves the issue there.

As a relatively inexperienced developer, I’m not entirely sure if this solution will be universally applicable, but I hope it helps someone!

Please is there any ETA for the fix of this issue. I am unable to make a serverless app that accepts azure service bus messages, due to that I have scaling issues.

I think I figured this out. @rhyskoedijk can you try with the latest SDK 1.16.3 and latest ServiceBus extension?

What I think is happening is for a bit we had a version of the SDK which would set the inner-build csproj’s TFM to be net7.0 if your project was net7.0. This causes a bug where now multi-targeted packages that had a net7.0 TFM would be brought in, and could end up depending on AspNetCore 7.0. This is what I see happening with your project. The generated WorkerExtension.csproj targets net7.0 and Grpc.AspNetCore.Server ends up depending on Microsoft.AspNetCore.Routing/7.0.0, which is not found when deployed since we only have the net6.0 of AspNetCore on the machine.

After updating the Worker SDK to latest on your project I saw Grpc.AspNetCore.Server now reference Microsoft.AspNetCore.Routing/6.0.0, which makes me believe it should work when deployed.

I was getting the same error as this locally after going to .Net 8 and moving to isolated model, what worked for me was changing my target framework from net8.0 to net8.0-windows

@Saibamen I followed the guide closely and updated the toolset in VS. I was able to get the function running locally using func start by adding the setting described here: https://github.com/Azure/azure-functions-dotnet-worker/issues/2335#issuecomment-1981613378

However, the issue still remains after pushing up the changes and redeploying through the pipeline. I’m wondering if there’s an issue with the yml file although it worked with no issues before moving from in-proc to isolated.

We are getting the same error when we upgraded from .net7 to .net8

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. at Microsoft.Extensions.DependencyInjection.GrpcServicesExtensions.AddGrpc(IServiceCollection services) at Microsoft.Azure.WebJobs.Extensions.Rpc.WebJobsExtensionBuilderRpcExtensions.AddCoreServices(IServiceCollection services) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Extensions.Rpc\WebJobsExtensionBuilderRpcExtensions.cs : 39 at Microsoft.Azure.WebJobs.Extensions.Rpc.WebJobsExtensionBuilderRpcExtensions.MapWorkerGrpcService[T](IWebJobsExtensionBuilder builder) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Extensions.Rpc\WebJobsExtensionBuilderRpcExtensions.cs : 31 at Microsoft.Extensions.Hosting.ServiceBusHostBuilderExtensions.AddServiceBus(IWebJobsBuilder builder,Action`1 configure) at Microsoft.Extensions.Hosting.ServiceBusHostBuilderExtensions.AddServiceBus(IWebJobsBuilder builder) at Microsoft.Azure.WebJobs.ServiceBus.ServiceBusWebJobsStartup.Configure(IWebJobsBuilder builder) at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureStartup(IWebJobsStartup startup,WebJobsBuilderContext context,IWebJobsBuilder builder) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs : 166 at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureAndLogUserConfiguredServices(IWebJobsStartup startup,WebJobsBuilderContext context,IWebJobsBuilder builder,ILoggerFactory loggerFactory) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs : 130 at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseWebJobsStartup(IWebJobsBuilder builder,Type startupType,WebJobsBuilderContext context,ILoggerFactory loggerFactory) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs : 115 at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseExternalStartup(IWebJobsBuilder builder,IWebJobsStartupTypeLocator startupTypeLocator,WebJobsBuilderContext context,ILoggerFactory loggerFactory) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs : 213 at Microsoft.Azure.WebJobs.Script.ScriptHostBuilderExtensions.<>c__DisplayClass7_0.<AddScriptHostCore>b__1(HostBuilderContext context,IWebJobsBuilder webJobsBuilder) at /src/azure-functions-host/src/WebJobs.Script/ScriptHostBuilderExtensions.cs : 226 End of inner exception
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>V4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <RootNamespace>xxxxxxxxxxx</RootNamespace>
        <LangVersion>default</LangVersion>
	</PropertyGroup>

	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
		<DefineConstants>DEBUG;TRACE</DefineConstants>
	</PropertyGroup>

	<PropertyGroup Condition="'$(BuildType)' == 'publish'">
		<PublishReadyToRun>true</PublishReadyToRun>
		<PublishSingleFile>true</PublishSingleFile>
		<PublishTrimmed>true</PublishTrimmed>
		<UseAppHost>true</UseAppHost>
		<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
	</PropertyGroup>

    <PropertyGroup>
        <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.15.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
    </ItemGroup>
    <ItemGroup>
        <None Update="appsettings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
    <ItemGroup>
        <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
    </ItemGroup>
</Project>

I’m seeing this locally on .NET 8.

Csproj:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0</TargetFramework>
		<AzureFunctionsVersion>v4</AzureFunctionsVersion>
		<OutputType>Exe</OutputType>
	</PropertyGroup>
	<ItemGroup>
		<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.15.0" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
		<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
	</ItemGroup>
	<ItemGroup>
		<None Update="host.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
		<None Update="local.settings.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
			<CopyToPublishDirectory>Never</CopyToPublishDirectory>
		</None>
	</ItemGroup>
</Project>
[2024-01-13T07:40:22.631Z] Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. Grpc.AspNetCore.Server: 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.

@alvipeo The .csproj content file you shared above does not have nuget packages for the .NET isolated function app, but it has the nuget package used by in-proc model app. So your app is not in isolated model, but in in-proc model.

See https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#core-packages

@jviau That worked! I removed -f net8.0 from my Github Action and now the function app runs fine. Thank you for your help!

Thanks for the explanation! I’m glad this issue is getting attention. Unfortunately our .NET 8 upgrade has stalled and I don’t want to go back to multi targeting. Thanks again

@KelvisGama the diagnostic source issue is different. That would be an explicit reference to that package by you or an extension. 7.0.0 of that package also is not supported on the host side (its fine to use for your worker in dotnet isolated, but WebJobs extensions cannot use it).

Unfortuantely my .NET 8 migration is at a standstill because of this issue

I’ve upgraded to the latest package(5.15.0) but still getting the same error. I’m using Isolated Function App and .Net 8

<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.15.0" />

If this remains broken, no one will be able to use Service Bus message settlement in isolated worker model for .NET Azure Functions

We have the same issue after updating Microsoft.Azure.Functions.Worker.Extensions.ServiceBus to the latest version. It doesn’t work with 5.14.0 as well.

@dush88c The project file you shared above does not look like the one for a dotnet isolated project. For dotnet in-proc apps, please open an issue in the host repo (https://github.com/Azure/azure-functions-host)