NullReferenceException when using AddAzureStorage with DefaultAzureCredential in Aspire.Hosting.Azure.Storage 9.5.2
- 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
When calling AddAzureStorage("name") in an AppHost project, the application throws a System.NullReferenceException originating from Azure.Identity.dll. This occurs during credential initialization when using a custom credential switch that falls back to DefaultAzureCredential. It seems that AddAzureStorage attempts to resolve TokenCredential even when the storage is expected to run using the Azurite emulator, likely because no explicit connection string or emulator configuration is provided.
### Expected Behavior
When running the AppHost with AddAzureStorage("name") and no explicit cloud credentials, the application should initialize the storage resource successfully without attempting to resolve TokenCredential or throwing any exceptions.
### Steps To Reproduce
```
var builder = DistributedApplication.CreateBuilder(args);
var storageDi = builder
.AddAzureStorage("name")
.RunAsEmulator(x =>
{
x.WithImageTag("latest");
});
builder.Build().Run();
```
### Exceptions (if any)
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Object reference not set to an instance of an object. at Azure.Identity.DefaultAzureCredentialFactory.TryCreateDevelopmentBrokerOptions(InteractiveBrowserCredentialOptions& options)
### .NET Version info
.NET SDK:
Version: 9.0.306
Commit: cc9947ca66
Workload version: 9.0.300-manifests.abe91478
MSBuild version: 17.14.28+09c1be848
### Anything else?
Contributor guide
Research direction
Start by running the supplied AppHost reproduction with AddAzureStorage and RunAsEmulator, then trace the AddAzureStorage resource setup and credential initialization path. Confirm that emulator startup with no explicit cloud credentials does not resolve TokenCredential or throw, and add or update coverage for this scenario if the relevant tests are found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100