azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] Function [XYZ]: cannot find value named 'ServiceBusConnection' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger'
Library name and version
microsoft.azure.webjobs.extensions.servicebus 5.8.1
Describe the bug
I have enabled Managed Identity together with ServiceBusTrigger in my Azure Function according to the official guide here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-identity-based-connections-tutorial-2.
Expected behavior
There is no MSBuild warning regarding missing setting in local.settings.json when using Managed Identity for Azure Functions.
Actual behavior
I get a warning: Function [X]: cannot find value named 'ServiceBusConnection' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger' C:....nuget\packages\microsoft.net.sdk.functions\4.1.3\build\Microsoft.NET.Sdk.Functions.Build.targets 32
I get this error both locally and on the build server.
Reproduction Steps
Prepare an Azure Function based on the official page here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-identity-based-connections-tutorial-2.
Content in local.settings.json:
"Values": { ..., "ServiceBusConnection:ConnectionStringWithoutSecret": "Endpoint=sb://namespace.servicebus.windows.net/;Authentication=ManagedIdentity", "ServiceBusConnection:fullyQualifiedNamespace": "namespace.servicebus.windows.net", "ServiceBusConnection:HostAddress": "sb://namespace.servicebus.windows.net" }
Environment
.NET 6 Windows 10 IDE: Visual Studio 17.4.4
Microsoft.NET.Sdk.Functions 4.1.3
Build agent running WS19
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @kristinannabel,
If you are attempting to use managed identity, you should not be specifying a connection string. Instead, you should have something like this in your "Values":
"MyConnection__fullyQualifiedNamespace": "namespace.servicebus.windows.net",
"MyConnection__credential": "managedidentity"
More details can be found here.
Hi @kristinannabel. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
/unresolve The warning is that there are no setting in local.settings.json that is named ServiceBusConnection, since my settings are ServiceBusConnection:Something...
Also, I need the connectionsStringWithoutSecret for this purpose:
.AddMassTransitForAzureFunctions(cfg =>
{
cfg.AddServiceBusMessageScheduler();
cfg.AddConsumer<MyConsumer>(typeof(MyConsumerDefinition));
}, ServicebusSettingsConst.ConnectionStringWithoutSecretName, ConfigureBus);
Please be aware that the connection string that you're specifying is invalid. The token Authentication=ManagedIdentity is not valid and will be ignored. As a result, that connection string will be rejected as malformed since there is no shared key name/value or SAS associated with it.
The warning is that there are no setting in local.settings.json that is named ServiceBusConnection, since my settings are ServiceBusConnection:Something...
The syntax you are using is not right - you need to use double underscore rather than colon as I showed in the snippet above. Also, as @jsquire mentions, the connection string you are using will not work because the Authentication token is not supported in the connection string.
@JoshLove-msft Ok, but how should my code-snippet look like? My code is actually working, so it cant be that far off. I just wanted to get ridd of the warning. I will try double underscore.
With these values, I still get the same error;
"ServiceBusConnection__fullyQualifiedNamespace": "namespace.servicebus.windows.net", "ServiceBusConnection__credential": "managedidentity",
Can you make sure you are using the latest Core Tools version?
Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
@JoshLove-msft Yes, I am using the latest Core Tools version.
The connection name you use in your settings needs to match the connection name used in your function. Can you confirm that they match?
Yes.
From Function: Connection = "ServiceBusConnection"
In local.settings.json:
"ServiceBusConnection__ConnectionStringWithoutSecret": "Endpoint=sb://namespace.servicebus.windows.net",
"ServiceBusConnection__HostAddress": "sb://namespace.servicebus.windows.net",
"ServiceBusConnection__fullyQualifiedNamespace": "namespace.servicebus.windows.net",
"ServiceBusConnection__credential": "managedidentity",
ServiceBusConnection__ConnectionStringWithoutSecret
You can't include both a connection string and the managed identity config. The extension has no knowledge of this settings "ConnectionStringWithoutSecret" and "HostAddress". If you want to use connection string config you would just set the connection string like this:
"ServiceBusConnection": "<connection string>"
If you need that other setting for some other integration, it would need to live under a different config, e.g. "MassTransitConnectionInfo". If you want to use managed identity config you would include only this:
"ServiceBusConnection__fullyQualifiedNamespace": "namespace.servicebus.windows.net",
"ServiceBusConnection__credential": "managedidentity",
Hi @kristinannabel. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
/unresolve
Ok, even with
"ServiceBusConnection__fullyQualifiedNamespace": "namespace.servicebus.windows.net", "ServiceBusConnection__credential": "managedidentity",
in local.settings.json, I still get the same error
Function [MyFunction]: cannot find value named 'ServiceBusConnection' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger'
C:\Users\kristintf\.nuget\packages\microsoft.net.sdk.functions\4.1.3\build\Microsoft.NET.Sdk.Functions.Build.targets 32
Can you please share your function app project so that I can repro locally?
@JoshLove-msft I'm not allowed to share any of our code. But can give you some bits, if thats helpful.
`
public class MyFunction {
private readonly string _queueName;
private readonly IMessageReceiver _receiver;
public MyFunction(IMessageReceiver receiver, ConnectionSettings settings)
{
_receiver = receiver ?? throw new ArgumentNullException(nameof(receiver));
_queueName = settings.QueueName;
}
[Disable("DisableServiceBusTriggerFunctions")]
[FunctionName("MyFunction")]
public async Task MyFunction([ServiceBusTrigger("%ConnectionSettings:QueueName%", Connection = "ServiceBusConnection")] ServiceBusReceivedMessage message, CancellationToken cancellationToken)
{
await _receiver.HandleConsumer<MyConsumer>(_queueName, message, cancellationToken);
}
}`
public class MyConsumer : IConsumer<IMyEvent> {
private readonly IMyAdapter _myAdapter;
private readonly ITelemetryLogger _telemetryLogger;
public MyConsumer(IMyAdapter myAdapter,
ITelemetryLogger telemetryLogger)
{
_myAdapter = myAdapter
?? throw new ArgumentNullException(nameof(myAdapter));
_telemetryLogger = telemetryLogger ?? throw new ArgumentNullException(nameof(telemetryLogger));
}
public async Task Consume(ConsumeContext<IMyEvent> context)
{
var message = context.Message;
_telemetryLogger.LoggId(message.Id);
await _myAdapter.Arkiver(message.Id);
}
}
Startup.cs:
services.AddHttpClient<IMyAdapter, MyAdapter>()
services.AddScoped<MyFunction>()
services.AddMassTransitForAzureFunctions(cfg =>
{
cfg.AddServiceBusMessageScheduler();
cfg.AddConsumer<MyConsumer>();
}, "Endpoint=sb://namespace.servicebus.windows.net/;Authentication=ManagedIdentity", ConfigureBus);
private void ConfigureBus(IBusRegistrationContext busRegistrationContext, IServiceBusBusFactoryConfigurator serviceBusBusFactory)
{
serviceBusBusFactory.ConfigureJsonSerializerOptions(settings =>
{
settings.NumberHandling = JsonNumberHandling.AllowReadingFromString;
return settings;
});
var config = busRegistrationContext.GetRequiredService<IConfiguration>();
serviceBusBusFactory.Host(new Uri(config["sb://namespace.servicebus.windows.net"]), conf =>
{
if (EnvironmentIsDevelopment())
{
conf.TransportType = Azure.Messaging.ServiceBus.ServiceBusTransportType.AmqpWebSockets;
}
conf.TokenCredential = new DefaultAzureCredential();
});
}
Can you please also include your complete local.settings.json file (redacting any secrets) as well as your csproj?
Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
Having the same issue - here's my local.settings.json (redacted):
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
...
"ServiceBusConnection:fullyQualifiedNamespace": "xxx.servicebus.windows.net",
...
"AZURE_TENANT_ID": "xxx",
"AzureFunctionsJobHost:Serilog:MinimumLevel:Default": "Debug"
},
"Host": {
"CORS": "http://localhost:3000"
}
}
and csproj (also redacted)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<UserSecretsId>f84e8ce6-e906-4a4a-b228-932d79a41e8f</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.13.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.13.0" />
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.1.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.9.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xxx.csproj" />
<ProjectReference Include="..\yyy.csproj" />
<ProjectReference Include="..\zzz.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Hi @kristinannabel, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!