Skip to content

Error "Invalid URI: The URI is empty." when running AppHost that contains Azure Key Vault emulator #10423

@MrClyfar

Description

@MrClyfar

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When starting up an Aspire AppHost that has a Key Vault created via RunAsEmulator(), I get an error related to the Key Vault which states that there is a missing URI:

Hosting failed to start
 System.UriFormatException: Invalid URI: The URI is empty.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
    at System.Uri..ctor(String uriString)
    at AzureKeyVaultEmulator.Aspire.Hosting.KeyVaultEmulatorLifecycleHelper.EnsureContainerStartAsync()
    at AzureKeyVaultEmulator.Aspire.Hosting.KeyVaultEmulatorLifecycleHelper.StartAsync(CancellationToken cancellationToken)
    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)

Expected Behavior

The Key Vault is created and available when the Aspire host is up and running.

Steps To Reproduce

Here is my AppHost setup for the Key Vault.

var storeHomeConnectionString = builder.AddParameter(
    name: "store-home-connectionstring",
    secret: true,
    value: "foobar");

var keyVault = builder
    .AddAzureKeyVault("keyvault")
    .ConfigureInfrastructure(infra =>
    {
        var resources = infra.GetProvisionableResources();
        var keyVaultResource = resources.OfType<KeyVaultService>().Single();

        var storeHomeConnectionStringSecret = new KeyVaultSecret("store-home-connectionstring")
        {
            Parent = keyVaultResource,
            Name = "store-home-connectionstring",
            Properties = new SecretProperties
            {
                Value = storeHomeConnectionString.AsProvisioningParameter(infra)
            }
        };

        infra.Add(storeHomeConnectionStringSecret);
    })
    .RunAsEmulator();

builder.AddProject<Projects.Home>(
        "Test-MTFE",
        project => project.LaunchProfileName = "Kestrel - Local Development Test - ISOLATED")
    .WithRelationship(propertyService.Resource, "References")
    .WithRelationship(authServer.Resource, "DependsOn")
    .WithReference(keyVault);

builder.Build().Run();

The call to builder.Build().Run(); throws the error.

I added the following to the environment variables section in the launchSettings.json file associated with the AppHost project:

"ConnectionStrings__keyvault": "https://localhost:4997/"

But this did not fix the issue. I also tried this in ConfigureInfrastructure()

keyVaultResource.Properties.VaultUri = new Uri("https://localhost:4997/");

but this also did not fix the problem.

I read that the default endpoint for the emulator is https://localhost:4997, and that it should be included in the environment variables for me. So I'm not sure if this is a bug, or just me not understanding how to configure/use the API properly.

Exceptions (if any)

 System.UriFormatException: Invalid URI: The URI is empty.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
    at System.Uri..ctor(String uriString)
    at AzureKeyVaultEmulator.Aspire.Hosting.KeyVaultEmulatorLifecycleHelper.EnsureContainerStartAsync()
    at AzureKeyVaultEmulator.Aspire.Hosting.KeyVaultEmulatorLifecycleHelper.StartAsync(CancellationToken cancellationToken)
    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)```

.NET Version info

.NET SDK:
 Version:           9.0.302
 Commit:            bb2550b9af
 Workload version:  9.0.300-manifests.183aaee6
 MSBuild version:   17.14.13+65391c53b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.302\

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.7
  Architecture: x64
  Commit:       3c298d9f00

.NET SDKs installed:
  8.0.412 [C:\Program Files\dotnet\sdk]
  9.0.205 [C:\Program Files\dotnet\sdk]
  9.0.302 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Here is the AppHost csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <Sdk Name="Aspire.AppHost.Sdk" Version="9.3.1" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UserSecretsId>343477fc-b7f9-4bc5-8a07-eff65218f187</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.1" />
    <PackageReference Include="Aspire.Hosting.Azure.KeyVault" Version="9.3.1" />
    <PackageReference Include="Azure.Provisioning.KeyVault" Version="1.1.0" />
    <PackageReference Include="AzureKeyVaultEmulator.Aspire.Hosting" Version="2.4.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Home\Home.csproj" />
  </ItemGroup>

</Project>

Anything else?

Visual Studio info:

Microsoft Visual Studio Professional 2022
Version 17.14.8
VisualStudio.17.Release/17.14.8+36301.6
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA870
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.14.114.53116
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.14.114.53116
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.14.114.53116
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.14.0-3.25326.11+bd4f2062291278e0df1e3fd3180c0c862495a3a7
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

ClaudiaIDE   3.1.47
This extension change the background image of editor.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GitHub Copilot   17.14.827.52834
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Keyboard Hero   1.0.14
Shows you what keyboard shortcuts you would benefit the most from learning based on your usage of Visual Studio

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NCrunch   
Continuous Testing Tool for .NET
Copyright � 2010-2025 Remco Software Ltd

NuGet Package Manager   6.14.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.14.3.2530601+3372435431977e91904a23ceb1eab689badc1bd9
Provides languages services for ASP.NET Core Razor.

Smooth Caret   2.0.0
Smooth caret movement effect for the Visual Studio text editor.

SQL Server Data Tools   17.14.26.0
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

Tweaks 2022   1.1.143
A collection of minor fixes and tweaks for Visual Studio to reduce the paper cuts and make you a happier developer

TypeScript Tools   17.0.40502.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.14.0-3.25326.11+bd4f2062291278e0df1e3fd3180c0c862495a3a7
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.14.0-beta.25230.7+c1a9d78ad4a474a716ccffb4367ed5151e3f7c9f
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VSColorOutput64   2023.4
Color output for build and debug windows - https://mike-ward.net/vscoloroutput

VsVim   2.10.0.6
VsVim is a Vim emulator for Visual Studio

WhereAmI   1.3.0
WhereAmI? An extension for whom is getting lost in the code.```

Metadata

Metadata

Assignees

No one assigned

    Labels

    azureIssues associated specifically with scenarios tied to using Azureazure-keyvault

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions