dotnet / dotnet/aspnetcore

[WebToolsE2E] After creating a Blazor Web App project with the ".dev.localhost TLD" selected, I added some code and ran it, but an exception occurred: System.Net.Http.HttpRequestException: 'No such host is known.'

Open
#64,050 1 comment 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

**REGRESSION INFO**: There is no "Use the .dev.localhost TLD in the application URL" option on 17.14.17

**INSTALL STEP**
1. Clean machine: Win11 x64 23H2 ENU
2. Install VS 18.0.0 Insiders 3 from https://aka.ms/vs/18/insiders/vs_Enterprise.exe

- Web workload
- Check 8.0/9.0 runtime
- Includes SDK 10.0 RC2

**REPRO STEPS**
1. File > New > Project > Blazor Web App > .NET 10.0 > WebAssembly ~ Global > Check "Use the .dev.localhost TLD in the application URL" > create.
2. Right click project BlazorSignalRApp.Client > select Manage NuGet Packages > install package 'Microsoft.AspNetCore.SignalR.Client'
3. Create a folder called 'Hubs' below BlazorSignalRApp
4. Right-click the Hubs folder to add a class called 'ChatHub.cs' and paste the following code
```
using Microsoft.AspNetCore.SignalR;

namespace BlazorSignalRApp.Hubs
{
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
}
```
5. In the BlazorSignalRApp project, open the Program.cs file and add the following code
```
builder.Services.AddSignalR();
builder.Services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
...
app.UseResponseCompression();
...
app.MapHub("/chathub");
```
6. In the BlazorSignalRApp.Client project, open the Pages/Home.razor file, replace with the following code
```
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavigationManager
@implements IDisposable



User:





Message:



Send



    @foreach (var message in messages)
    {
  • @message

  • }

@code {
#nullable disable warnings
private HubConnection hubConnection;
private List messages = new List();
private string userInput;
private string messageInput;

protected override async Task OnInitializedAsync()
{
hubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/chathub"))
.Build();

hubConnection.On("ReceiveMessage", (user, message) =>
{
var encodedMsg = $"{user}: {message}";
messages.Add(encodedMsg);
StateHasChanged();
});

await hubConnection.StartAsync();
}

Task Send() =>
hubConnection.SendAsync("SendMessage", userInput, messageInput);

public bool IsConnected =>
hubConnection.State == HubConnectionState.Connected;

public void Dispose()
{
_ = hubConnection.DisposeAsync();
}
}
```
7. Build and run

**NOTE**: Change step 7 to do 'dotnet run' using the CLI, this issue will also be reproduced.

**ACTUAL**:
The project cannot be run.
System.Net.Http.HttpRequestException: 'No such host is known. (blazorsignalrapp.dev.localhost:7211)'

Image

**EXPECTED**
The project can run successfully

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.