dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.83k stars 457 forks source link

[WebToolsE2E][Aspire] After adding Aspire.Azure.Security.KeyVault component, publish failed with 'ContainerCrashing' error: System.ArgumentNullException: Value cannot be null. (Parameter 'uriString') #2613

Closed v-cazhang closed 8 months ago

v-cazhang commented 8 months ago

REGRESSION INFO: Also repro on 8.0.0-preview.3.24105.21

INSTALL STEPS

  1. Clean machine: Win11 x64 23h2 ENU
  2. Install 17.10.0 Preview 2.0 [34701.141.d17.10] (Includes Aspire 8.0.0-preview.4.24129.7)
  3. Apply NuGet Feeds
  4. Install Docker Dektop
  5. Install azd

REPRO STEPS

  1. New Project > ASP.NET Core Empty project > name it 'AspireKeyVault'> 8.0 > check 'Enlist in Aspire Orchestration'

  2. Right-click AspireKeyVault project > Add > Aspire component > Aspire.Azure.Security.KeyVault

  3. Update the Program.cs of AspireKeyVault project with following codes:

    using Azure.Identity; 
    
    var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
    builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new VisualStudioCredential());
    
    //app.MapGet("/", () => "Hello World!");

    string? _mySecret = builder.Configuration["myAppSetting"]; var result = string.IsNullOrEmpty(_mySecret) ? "Null" : _mySecret; app.MapGet("/", async context => { await context.Response.WriteAsync($"Secret is {result}"); });

  4. Right-click the AspireKeyVault.AppHost > Publish > Azure Container Apps for .NET Aspire > next

  5. Under 'AzDev Environment', select following settings > next

    • Subscription name: WTE
    • Location: select any location
    • Environment name: type your own name
  6. Under 'Aspire Services', check AspireKeyVault, click 'Finish' > 'Close'

  7. Click 'Publish' button on the summary page.

  8. After publish finished, open 'Resource group', click AspireKeyVault

Notes:

  1. It will meet Bug 1985774 when adding the aspire component.
  2. It will meet https://github.com/dotnet/aspire/issues/2610 when running the solution.

ACTUAL Open AspireKeyVault container app shows 'ContainerCrashing'. image Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'uriString') at System.ArgumentNullException.Throw(String paramName) at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName) at System.Uri..ctor(String uriString) at Program.

$(String[] args) in C:\Users\v-cazhang\source\repos\AspireKeyVault\AspireKeyVault\Program.cs:line 6

EXPECTED Doesn't show container crashing error.

balachir commented 8 months ago

Did F5 work successfully? I suspect that the VaultUri was not set correctly during deployment. Closing this in favor of https://github.com/dotnet/aspire/issues/2621 where I've added a lot more details. We can revisit this issue in our sync if you think that this is a different issue.

v-cazhang commented 8 months ago

Hi @balachir , for this issue, I also try to use the key vault created by VS, and F5 can work successfully this time. But publish still reproduces this issue. image image

balachir commented 7 months ago

@v-cazhang you mention that publish still has issue. Does the publish issue still reproduce using Aspire P5? If yes, can you open a new issue using Aspire P4 / Aspire P5 in the repro steps and add it to our Issues Summary page so that we can track.