The generated SQL Script isn’t found when running NServiceBus within Azure Functions using the 0.5.0 NServiceBus.AzureFunctions.ServiceBus packade (along side the 6.0.4 NServiceBus.Persistence.Sql).
The endpoint is looking in different locations based on how we start the function:
Different locations based on how we start the endpoint:
Visual Studio:
System.Private.CoreLib: Exception while executing function: Core. NServiceBus.Persistence.Sql: Expected 'C:\Program Files\Microsoft\Azure Functions Core Tools\NServiceBus.Persistence.Sql\MsSqlServer\Outbox_Create.sql' to exist. It is possible it was not deployed with the endpoint.
Rider 2020.3:
System.Private.CoreLib: Exception while executing function: Core. NServiceBus.Persistence.Sql: Expected 'C:\Users\username\AppData\Roaming\JetBrains\Rider2020.3\azure-functions-coretools\3.0.3233\NServiceBus.Persistence.Sql\MsSqlServer\Outbox_Create.sql' to exist. It is possible it was not deployed with the endpoint.
func start from the CLI:
System.Private.CoreLib: Exception while executing function: Core. NServiceBus.Persistence.Sql: Expected 'C:\Users\username\AppData\Local\AzureFunctionsTools\Releases\3.18.0\cli_x64\NServiceBus.Persistence.Sql\MsSqlServer\Outbox_Create.sql' to exist. It is possible it was not deployed with the endpoint.
Unfortunately, you’re running into a side effect of how Azure Functions work, in that they are actually run by a precompiled exe that dynamically loads your assembly.
var configuration = new ServiceBusTriggeredEndpointConfiguration(AzureServiceBusTriggerFunction.EndpointName, "AzureServiceBus_ConnectionString");
var settings = configuration.AdvancedConfiguration.GetSettings();
settings.Set("SqlPersistence.ScriptDirectory", basePath);
I believe you don’t need IsDevelopmentEnvironment() method and custom basePath logic. You could get the base from the Functions context directly in the following way:
builder.GetContext().ApplicationRootPath;
Where builder is IFunctionsHostBuilder.
Your UseNServiceBus method would look like this:
var configuration = new ServiceBusTriggeredEndpointConfiguration(
AzureServiceBusTriggerFunction.EndpointName, "AzureServiceBus_ConnectionString");
var settings = configuration.AdvancedConfiguration.GetSettings();
settings.Set("SqlPersistence.ScriptDirectory", builder.GetContext().ApplicationRootPath);
This should work for any environment. Have a go at it and see if it’s working for you.