Open v-yuwzh opened 2 months ago
Could you post the errors from the console in VS or VSCode?
@vicperdana, the error information for eShopLite\Store\bin\Debug\net8.0\Store.exe as below:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7085
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5158
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\aa\eShopLite\Store
info: System.Net.Http.HttpClient.ProductService.LogicalHandler[100]
Start processing HTTP request GET http://localhost:5200/api/Product
info: System.Net.Http.HttpClient.ProductService.ClientHandler[100]
Sending HTTP request GET http://localhost:5200/api/Product
fail: Store.Services.ProductService[0]
Error during GetProducts.
System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it. (localhost:5200)
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Store.Services.ProductService.GetProducts() in C:\aa\eShopLite\Store\Services\ProductService.cs:line 21
the information for eShopLite\Products\bin\Debug\net8.0\Products.exe as below:
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (41ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "type" = 'table' AND "rootpage" IS NOT NULL;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (
SELECT 1
FROM "Product" AS "p")
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7130
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5228
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\aa\eShopLite\Products
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "p"."Id", "p"."Description", "p"."ImageUrl", "p"."Name", "p"."Price"
FROM "Product" AS "p"
Could you paste in your AppHost
Program.cs?
@vicperdana, in solution "eShopLite", there is no AppHost project,
so I provide program.cs in Products as below:
using Microsoft.EntityFrameworkCore;
using Products.Data;
using Products.Endpoints;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ProductDataContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("ProductsContext") ?? throw new InvalidOperationException("Connection string 'ProductsContext' not found.")));
// Add services to the container.
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapProductEndpoints();
app.UseStaticFiles();
app.CreateDbIfNotExists();
app.Run();
provide Program.cs in Store as below:
using Store.Components;
using Store.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<ProductService>();
builder.Services.AddHttpClient<ProductService>(c =>
{
var url = builder.Configuration["ProductEndpoint"] ?? throw new InvalidOperationException("ProductEndpoint is not set");
c.BaseAddress = new(url);
});
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
This doesn't seem related to Aspire, but to run this successfully, you'll need to ensure that the applicationUrl
in Products launchSettings.json
is defined exactly the same per appSettings.json
ProductEndpoint
in Store.
The default config seems to point to different address http://localhost:5200
vs http://localhost:5228
@vicperdana ,
After I ensure that the applicationUrl
in ProductslaunchSettings.json
is defined exactly the same per appSetting.json ProductEndpoint in Store.
this issue works well, first thanks for you suggestion, for the user, need change applicationUrl value is unfriendly to the user after clone this solution, could you help to update this solution or do you know who is owner for this solution? Thanks in advance.
I am not aware - perhaps raise an issue here?
Can you please PR the sample
INSTALL STEPS
REPRO STEPS
Note: When do scenario Tutorial: Add .NET Aspire to an existing .NET 8 microservices app meet this issue, can refer this for details information.
ACTUAL: Show "There is a problem loading our products, Please try again later"![image](https://github.com/dotnet/aspire-samples/assets/41678874/f59d0021-af48-4204-a003-03984c1bd323)
EXPECTED Page show with no problem.