Open mercedesyenzzz opened 1 month ago
Could you provide a bit more detail about your setup. What is in your apphost?
I am using .NET SDK 8.0.300 & I am developing on WSL2 (Ubuntu 22.04.4 LTS)
My apphost is very basic. But for testing I trimmed it down to this now:
using Projects;
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<MyAPI>("my-api");
builder.Build().Run();
Also with this minimalistic config I am getting the error (Aspire version 8.0.1). In my API project I am using these Aspire Nuget packages:
<PackageReference Include="Aspire.Azure.Security.KeyVault" Version="8.0.1" />
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
I could figure out that this is related to Aspire.Azure.Security.KeyVault
. When I have this package in my csproj I am getting the error message from above. This is also the case when I am not registering the service via:
builder.Configuration.AddAzureKeyVaultSecrets("secrets");
in my Program.cs
.
I noticed that you are saying that you are using Aspire.Azure.Security.KeyVault
and Aspire.Microsoft.EntityFrameworkCore.SqlServer
but you don't have any calls to AddAzureKeyVault(...)
or AddSqlServer(...)
in your AppHost.
Does this mean that you are manually configuring the connection strings for those in your MyAPI project's appsettings/user secrets?
You can let Aspire help you here by just doing this:
var builder = DistributedApplication.CreateBuilder(args);
var db = builder.AddSqlServer("sql").AddDatabase("db");
var kv = builder.AddAzureKeyVault("kv");
builder.AddProject("my-api")
.WithReference(db)
.WithReference(kv);
When you run, Aspire will take care of creating the KeyVault resource and also spinning up the SQL server in a container.
Yes I know that but I am using databases that do already exist on different servers. So to connect to them in dev I put in the ConnectionString in the format described above into dotnet user secrets
. I played around with the Azure KeyVault
component because I am planning to use that in production.
However, the issue that I was facing is still very strange in my opinion. I have different microservices that are connected to different (already existing) databases. I have one microservice that is also connected to an SQL Server DB
but uses SQL Authentication
. Not facing any issues in this case also when I am using the Aspire.Azure.Security.KeyVault Nuget package
in that application.
For a pre-existing database you should be using the following:
var db = builder.AddConnectionString("preexisting");
Then for your user secrets you want to add one for ConnectionStrings:preexisting
with the connection string to that database. Aspire will pick that up and pass it in as a reference.
@mercedesyenzzz did this solve the issue for you?
@mitchdenny I wanted to chime in here. I am having a similar issue with the latest SqlClient / Azure.Identity and service principal auth without using .net aspire. The exact same exception… it seems to be sending invalid parameters to the MS OAuth endpoint.
I think this is a bug outside of aspire, I need to do more PoC today and report this because it’s causing issues for a few of our apps that recently updated these as part of a transitive package.
Thanks for the heads up. If you do get a repro can you share it here too? Especially if you raise an issue elsewhere, it'll help us keep track of things.
Do you have any updates or a good workaround for this ?
It is currently a big blocker for us -.-
@leetmike did you already reported that issue?
Did some more troubleshooting. I don't think that this issue is related to Azure.Identity
. When I use:
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.1" />
instead of
<PackageReference Include="Aspire.Azure.Security.KeyVault" Version="8.0.2" />
everything works fine.
Hi,
I have noticed that there is an issue since Aspire
8.0.0-preview.7.24251.11
.With
8.0.0-preview.6.24214.1
I could just run this without any issues:builder.AddSqlServerDbContext<AppDbContext>("test-db");
together with a .NET user-secret in this format:
"ConnectionStrings:test-db" "Server=servernamehere; Authentication=Active Directory Service Principal; Encrypt=True; Database=databasenamehere; User Id=UserID; Password=Password;"
Since preview 7 I am getting the following error when I am using the
AppDbContext
somewhere in my app. When I do not useService Principal Authentication
I am not facing any issues.This is the full error that I am getting: