-
Is there an existing issue for this?
Describe the bugThis is duplicate of issue reported in eShop, but it needs more love, so adding it here. It is on Mac, but I think it is irrelevant. Calling Console.WriteLine($"IP {apiService.GetEndpoint("http").Url}"); crashes with:
Expected BehaviorShould handle Exception at least. Steps To ReproduceCleanup rm -fr AppAspireRepro/ Create minimal sample dotnet new aspire-starter -o AppAspireRepro Run: dotnet run --project AppAspireRepro/AppAspireRepro.AppHost/AppAspireRepro.AppHost.csproj Now add: Console.WriteLine($"IP {apiService.GetEndpoint("http").Url}");
Console.WriteLine($"IP {apiService.GetEndpoint("https").Url}"); before: builder.Build().Run(); Run again dotnet run --project AppAspireRepro/AppAspireRepro.AppHost/AppAspireRepro.AppHost.csproj and watch Der Untergang:
Exceptions (if any)
.NET Version info
Anything else?
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
It seems you try get Endpoint url before host started, endpoint allocated when host completly started. |
Beta Was this translation helpful? Give feedback.
-
Thanks for help.
Not sure about that. OK. I am not Aspire expert, but I remember I tried a lot of variants. Have you tried to repro? It is quite simple. OK. Trying. Changed var a = builder.Build();
Console.WriteLine($"IP {apiService.GetEndpoint("http").Url}");
Console.WriteLine($"IP {apiService.GetEndpoint("https").Url}");
a.Run(); The same result. I think placing code after There are several comments in eShop repo (issue I linked) |
Beta Was this translation helpful? Give feedback.
-
Endpoint allocated after |
Beta Was this translation helpful? Give feedback.
-
Confirmed (tested): Code: var a = builder.Build();
a.Run();
Console.WriteLine($"IP {apiService.GetEndpoint("http").Url}");
Console.WriteLine($"IP {apiService.GetEndpoint("https").Url}"); Does not throw, but cannot be used.
Nope. Info about IP address is needed eariler. |
Beta Was this translation helpful? Give feedback.
-
The eshop bug is for a different reason. It's because when you run on the command line, the http launch profile is selected and there's no https endpoint defined. The above is because you are resolving it too early. If you want to print the endpoint then you can resolve it after Starting: var builder = DistributedApplication.CreateBuilder(args);
var appA = builder.AddNpmApp("app-a", "../app-a")
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();
var httpEndpoint = appA.GetEndpoint("http");
var app = builder.Build();
app.Start();
Console.WriteLine($"URL: {httpEndpoint.Url}");
app.WaitForShutdown(); |
Beta Was this translation helpful? Give feedback.
See https://gist.github.com/davidfowl/b408af870d4b5b54a28bf18bffa127e1#endpoint-primitives