Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppHost project crashes on startup: System.UriFormatException: Invalid URI: The hostname could not be parsed. #5587

Closed
1 task done
SapiensAnatis opened this issue Sep 7, 2024 · 1 comment · Fixed by #5588
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Milestone

Comments

@SapiensAnatis
Copy link

SapiensAnatis commented Sep 7, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hey, just trying to integrate Aspire into my existing solution. The first time I tried it, it threw this on startup:

System.UriFormatException: Invalid URI: The hostname could not be parsed.

I eventually narrowed this down to using an applicationUrl of "http://*:80" in my web API's launchSettings.json. I had this set to listen on all IP addresses as I need to connect to my web API from my smartphone.

Expected Behavior

This is my first time using Aspire so I don't have the context to know why it reads launchSettings, but perhaps these URLs could be skipped. I think in any case the error message could be improved, as I only narrowed it to launchSettings by checking the Aspire source code.

Steps To Reproduce

  1. Create new Web API project
  2. Set applicationUrl to http://*:80 in the web API's launchSettings.json:
{
    "$schema": "https://json.schemastore.org/launchsettings.json",
    "profiles": {
        "DragaliaAPI": {
            "commandName": "Project",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development",
            },
            "applicationUrl": "http://*:80"
        }
    }
}
  1. Create new Aspire app host with this configuration:
var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.DragaliaAPI>("dragaliaapi");

builder.Build().Run();
  1. Crash

Exceptions (if any)

Unhandled exception. System.UriFormatException: Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at Aspire.Hosting.ProjectResourceBuilderExtensions.WithProjectDefaults(IResourceBuilder`1 builder, ProjectResourceOptions options) in /_/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs:line 407
   at Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject[TProject](IDistributedApplicationBuilder builder, String name, Action`1 configure) in /_/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs:line 216
   at Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject[TProject](IDistributedApplicationBuilder builder, String name) in /_/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs:line 63
   at Program.<Main>$(String[] args) in C:\Users\jay0\Projects\Dawnshard\AppHost\Program.cs:line 3

.NET Version info

.NET SDK:
 Version:           8.0.401
 Commit:            811edcc344
 Workload version:  8.0.400-manifests.57f7c351
 MSBuild version:   17.11.4+37eb419ad

Anything else?

Aspire.Hosting.AppHost v8.2.0.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Sep 7, 2024
@davidfowl
Copy link
Member

http://*:80 looks to be the problem.

@davidfowl davidfowl added the bug label Sep 7, 2024
@davidfowl davidfowl self-assigned this Sep 8, 2024
@davidfowl davidfowl added this to the 9.0 milestone Sep 8, 2024
davidfowl added a commit that referenced this issue Sep 8, 2024
- As part of this change expose TargetHostAddress on EndpointAnnotation which describes the original address that was bound to in both the kestrel endpoint list and the launch profile's application urls.
- Added a test

Fixes #5587
davidfowl added a commit that referenced this issue Sep 9, 2024
* Handle parsing wildcard urls in launch profiles
- As part of this change expose TargetHostAddress on EndpointAnnotation which describes the original address that was bound to in both the kestrel endpoint list and the launch profile's application urls.
- Tell DCP about the target host
- Added a test

Fixes #5587
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants