Azure function rewriting environment problem
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
For Aspire - 9.1.0-preview.1.24561.5, I am experiencing a problem regarding poor loading of environments settings for Azure Function. I wrote about it [here](https://github.com/dotnet/aspire/issues/920) and was directed to create a new bug.
The problem occurred in previous versions as well.
I have in AzureFunctionsTest.Functions local.settings.json with empty values and in AzureFunctionsTest.AppHost added connection strings to appsettings with filled values.
I then register the connection strings in Aspire program.cs and then add them as with refrence to the Azure Function. However, if I use debug to look at the values loaded in configuration in program.cs in Azure Function, sometimes they are all filled, sometimes they are all empty, and most often it varies.
I have prepared a repository - https://github.com/petrkasnal/AspireLocalSettingsProblem
Aspire
```
var messaging = builder.AddConnectionString("Messaging");
var messaging2 = builder.AddConnectionString("Messaging2");
var messaging3 = builder.AddConnectionString("Messaging3");
var messaging4 = builder.AddConnectionString("Messaging4");
var messaging5 = builder.AddConnectionString("Messaging5");
var messaging6 = builder.AddConnectionString("Messaging6");
builder.AddAzureFunctionsProject("funcapp")
.WithReference(messaging)
.WithReference(messaging2)
.WithReference(messaging3)
.WithReference(messaging4)
.WithReference(messaging5)
.WithReference(messaging6);
```
Aspire - local.settings
```
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"ServiceBusConnection__fullyQualifiedNamespace": ""
},
"ConnectionStrings": {
"Messaging": "",
"Messaging2": "",
"Messaging3": "",
"Messaging4": "",
"Messaging5": "",
"Messaging6": ""
}
}
```
Function
```
var value = builder.Configuration.GetConnectionString("Messaging");
var value2 = builder.Configuration.GetConnectionString("Messaging2");
var value3 = builder.Configuration.GetConnectionString("Messaging3");
var value4 = builder.Configuration.GetConnectionString("Messaging4");
var value5 = builder.Configuration.GetConnectionString("Messaging5");
var value6 = builder.Configuration.GetConnectionString("Messaging6");
```
Function - appsettings.json
```
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
},
"ConnectionStrings": {
"Messaging": "test.servicebus.windows.net",
"Messaging2": "test.servicebus.windows.net",
"Messaging3": "test.servicebus.windows.net",
"Messaging4": "test.servicebus.windows.net",
"Messaging5": "test.servicebus.windows.net",
"Messaging6": "test.servicebus.windows.net"
}
}
```
Results - Its totally randoml:




### Expected Behavior
I would expect the same behavior as the API, where only the values set in Aspire are loaded.
### Steps To Reproduce
Open repository - https://github.com/petrkasnal/AspireLocalSettingsProblem
Start Aspire application
Set breakpoint to AzureFunctionsTest.Functions - Program.cs
Run it a few times to see that the values go differently
### Exceptions (if any)
_No response_
### .NET Version info
9.0.0-rc.2.24473.5
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.