-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Describe the bug
Description
When updating a Functions app using version 4.4 of the package on .NET 6 to .NET 8, the Functions app will no longer load due to an assembly load issue when NServiceBus attempts to initialize:
Error configuring services in an external startup class. NServiceBus.Core: Could not load '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/bin/System.ClientModel.dll'. Consider excluding that assembly from the scanning. System.Private.CoreLib: Assembly with same name is already loaded.
Expected behavior
The app should start normally.
Actual behavior
Unfortunately, this is a known side effect of the in-process Azure Functions shared environment, because the user's app shares process space with host assemblies, leading to inevitable assembly loading issues especially when changing to different versions of .NET since version 4.4 of the NServiceBus Functions package targeting NServiceBus v8 was built on .NET 6 with .NET 6 dependencies that are also present in the .NET 8 hosting model.
These problems are a big part of the reason why Microsoft has deprecated the in-process hosting model and will stop supporting it altogether in November 2026.
Versions
NServiceBus.AzureFunctions.InProcess.ServiceBus 4.4.x are affected. Later versions of the component already target .NET 8.
Steps to reproduce
- Update in-process Functions app to .NET 8
- In the
local.settings.jsonfile, set"FUNCTIONS_INPROC_NET8_ENABLED": 1to notify the host to use the .NET 8 version of the Functions host. - Endpoint will not start.
Relevant log output
FUNCTIONS_INPROC_NET8_ENABLED app setting enabled in local.settings.json
Selected inproc8 host.
Starting child process for inproc8 model host.
/usr/lib/azure-functions-core-tools/in-proc8/func present
Started child process with ID: 3709
%%%%%%
%%%%%%
@ %%%%%% @
@@ %%%%%% @@
@@@ %%%%%%%%%%% @@@
@@ %%%%%%%%%% @@
@@ %%%% @@
@@ %%% @@
@@ %% @@
%%
%
Azure Functions Core Tools
Core Tools Version: 4.1.0+9a53409b640bbb39ef49467f000f46c5d81d4bbf (64-bit)
Function Runtime Version: 4.40.100.25262
Connection refused (localhost:7076)
[2025-08-07T20:38:34.704Z] Found /home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/IntegrationTests.HostV4.csproj. Using for user secrets file configuration.
Skipping 'AzureWebJobsServiceBus' from local settings as it's already defined in current environment variables.
[2025-08-07T20:38:35.026Z] Building host: version spec: , startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '84e403c3-ed1b-4495-85f1-f66946fdafc0'
[2025-08-07T20:38:35.052Z] Reading host configuration file '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/host.json'
[2025-08-07T20:38:35.053Z] Host configuration file read:
[2025-08-07T20:38:35.053Z] ***
[2025-08-07T20:38:35.053Z] "version": "2.0",
[2025-08-07T20:38:35.053Z] "extensions": ***
[2025-08-07T20:38:35.053Z] "ServiceBus": ***
[2025-08-07T20:38:35.053Z] "EnableCrossEntityTransactions": ***
[2025-08-07T20:38:35.053Z] ***
[2025-08-07T20:38:35.053Z] ***
[2025-08-07T20:38:35.053Z] ***
[2025-08-07T20:38:35.064Z] Extension Bundle not loaded. Loading extensions from /home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/bin. BundleConfigured: False, PrecompiledFunctionApp: False, LegacyBundle: False, DotnetIsolatedApp: False, isLogicApp: False
[2025-08-07T20:38:35.065Z] Script Startup resetting load context with base path: '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/bin'.
[2025-08-07T20:38:35.069Z] Loading startup extension 'Startup'
[2025-08-07T20:38:35.107Z] Loaded extension 'Startup' (1.0.0.0)
[2025-08-07T20:38:35.116Z] Loading startup extension 'ServiceBus'
[2025-08-07T20:38:35.116Z] Loaded extension 'ServiceBus' (5.16.4.0)
[2025-08-07T20:38:35.121Z] Reading host configuration file '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/host.json'
[2025-08-07T20:38:35.121Z] Host configuration file read:
[2025-08-07T20:38:35.121Z] ***
[2025-08-07T20:38:35.121Z] "version": "2.0",
[2025-08-07T20:38:35.121Z] "extensions": ***
[2025-08-07T20:38:35.121Z] "ServiceBus": ***
[2025-08-07T20:38:35.121Z] "EnableCrossEntityTransactions": ***
[2025-08-07T20:38:35.121Z] ***
[2025-08-07T20:38:35.121Z] ***
[2025-08-07T20:38:35.121Z] ***
[2025-08-07T20:38:35.249Z] Error configuring services in an external startup class.
[2025-08-07T20:38:35.249Z] Error configuring services in an external startup class. NServiceBus.Core: Could not load '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/bin/System.ClientModel.dll'. Consider excluding that assembly from the scanning. System.Private.CoreLib: Assembly with same name is already loaded.
[2025-08-07T20:38:41.530Z] Stopping the flush logs timer.
[2025-08-07T20:38:41.530Z] We couldn’t reach the Table service endpoint specified in the 'AzureWebJobsStorage' setting. We are unable to record diagnostic events, so the diagnostic logging service is being stopped. Please confirm network connectivity and endpoint accessibility.
[2025-08-07T20:38:41.530Z] Azure.Core: Connection refused (127.0.0.1:10002). System.Net.Http: Connection refused (127.0.0.1:10002). System.Net.Sockets: Connection refused.
[2025-08-07T20:38:41.541Z] A host error has occurred during startup operation '84e403c3-ed1b-4495-85f1-f66946fdafc0'.
[2025-08-07T20:38:41.541Z] Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. NServiceBus.Core: Could not load '/home/runner/work/NServiceBus.AzureFunctions.InProcess.ServiceBus/NServiceBus.AzureFunctions.InProcess.ServiceBus/src/IntegrationTests.HostV4/bin/Release/net6.0/bin/System.ClientModel.dll'. Consider excluding that assembly from the scanning. System.Private.CoreLib: Assembly with same name is already loaded.
Value cannot be null. (Parameter 'provider')
[2025-08-07T20:38:41.552Z] Host startup operation has been canceled
[2025-08-07T20:38:41.552Z] Initialization cancellation requested by runtime.
[2025-08-07T20:38:41.555Z] Stopping host...
[2025-08-07T20:38:41.555Z] Host shutdown completed.Additional Information
Workarounds
In order of preference:
- Migrate the app from the in-process model to the isolated worker model
- Update NServiceBus.AzureFunctions.InProcess.ServiceBus to version 5.x or 6.x, which includes updating NServiceBus to version 9 and requires at least .NET 8.
- Configure the NServiceBus assembly scanner to ignore the
System.ClientModel.dllassembly like this:
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.UseNServiceBus(c =>
{
// Other configuration here
// This line tells NServiceBus to ignore the problematic assembly
c.AdvancedConfiguration.AssemblyScanner().ExcludeAssemblies("System.ClientModel.dll");
});
}
}
See the PR that made this update for the component tests for more details.
Possible solutions
Warning
Because the bug only affects an outdated version of the component, the Azure Functions in-process model has already been deprecated, and there is a one-line workaround, the chances that this bug will be patched and released is slim.
The component contains a list of assemblies to exlude from scanning in all cases. System.ClientModel.dll could be added to that list.
Additional information
None