Skip to content

docs: modernize SignalR integration tutorial - #23992

Draft
Jen-Uno wants to merge 1 commit into
masterfrom
docs/signalr-tutorial-modernize
Draft

Jen-Uno wants to merge 1 commit into
masterfrom
docs/signalr-tutorial-modernize

Conversation

@Jen-Uno

@Jen-Uno Jen-Uno commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Modernizes the SignalR integration tutorial (doc/articles/signalr.md):

  • Rewrites the intro to describe ASP.NET Core SignalR and its transports, and when it's a good fit for Uno apps.
  • Updates prerequisites to .NET 9 SDK, Visual Studio 2022 17.8+ / VS Code / Rider, and clarifies that an Azure account is not required (local dev + production hosting pointers).
  • Replaces the Startup.cs / ConfigureServices pattern with the current Program.cs minimal-hosting model.
  • Uses the dotnet new web + dotnet add package Microsoft.AspNetCore.SignalR.Client CLI flow, structured into clear "Create the server" / "Add SignalR to the Uno client" steps.
  • Notes cross-platform client support (WASM, Desktop/Skia, iOS, Android) and adds production CORS guidance.

Why it's a separate PR

This content was originally authored on the Algolia DocSearch branch (PR #22789 / issue #22788) but is unrelated to search infrastructure. Per the review recap in unoplatform/uno-private#2038, unrelated content changes should be tracked and merged separately — so it's split out here.

Fixes #22607

🤖 Generated with Claude Code

Rewrites the SignalR tutorial to address multiple issues reported in #22607:
- Updates from .NET 5/VS2019/Startup.cs to .NET 9+ minimal API (Program.cs)
- Removes confusing AddRazorPages()/MapRazorPages() references
- Adds complete Uno client-side code (HubConnection, XAML UI)
- Adds CORS configuration guidance for WASM cross-origin scenarios
- Documents supported platforms and transport details
- Adds reconnection handling patterns
- Links to Microsoft docs and the ChatSignalR sample app

Fixes #22607
Copilot AI lite review requested due to automatic review settings August 6, 2026 17:14
@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Modernizes the Uno Platform SignalR integration tutorial to reflect current ASP.NET Core hosting patterns, tooling, and cross-platform client considerations.

Changes:

  • Updates the intro/prereqs and restructures the tutorial into server/client/run steps using modern .NET + minimal hosting.
  • Replaces Startup.cs guidance with Program.cs, adds CORS guidance, and includes reconnection + platform notes.
  • Adds updated samples (Hub, Program.cs, Uno client code-behind + XAML) and links to further reading.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/articles/signalr.md

1. Create `ASP.NET Core web application` in Visual Studio and name it `UnoChat.Service`.
Create a new ASP.NET Core Web API project that will host the SignalR hub:

Comment thread doc/articles/signalr.md
## Step 1 — Create the SignalR server

1. Create `ASP.NET Core web application` in Visual Studio and name it `UnoChat.Service`.
Create a new ASP.NET Core Web API project that will host the SignalR hub:
Comment thread doc/articles/signalr.md
Comment on lines +71 to +82
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", policy =>
{
endpoints.MapRazorPages();
endpoints.MapHub<Hubs.[YourProjectHub]>("/yourProjectHub");
policy
.AllowAnyHeader()
.AllowAnyMethod()
// In production, replace with your app's specific origin(s).
.SetIsOriginAllowed(_ => true)
.AllowCredentials();
});
```
});
Comment thread doc/articles/signalr.md
Comment on lines +93 to +94
> [!IMPORTANT]
> When your Uno WASM app is served from a different origin than the SignalR server, CORS must be configured on the server. The example above uses `SetIsOriginAllowed(_ => true)` for development convenience. In production, restrict this to your app's actual origin(s) and use `AllowCredentials()` since SignalR requires it for certain transports.
Comment thread doc/articles/signalr.md
Comment on lines +259 to +264
| Platform | Transport | Notes |
|----------|-----------|-------|
| WebAssembly | WebSockets | Requires CORS on the server. The `Microsoft.AspNetCore.SignalR.Client` NuGet package works in Uno WASM without additional configuration. |
| Desktop (Skia) | WebSockets | Works out of the box on Windows, macOS, and Linux. |
| iOS / Android | WebSockets | Works out of the box. Ensure the server URL is reachable from the device or emulator (avoid `localhost`; use the machine's IP or a tunnel such as [dev tunnels](https://learn.microsoft.com/azure/developer/dev-tunnels/overview)). |
| Windows (WinUI) | WebSockets | Works out of the box. |
Comment thread doc/articles/signalr.md
private async void ChatPage_Loaded(object sender, RoutedEventArgs e)
{
_connection = new HubConnectionBuilder()
.WithUrl("https://localhost:5001/chatHub")
Comment thread doc/articles/signalr.md

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://localhost:5001/chatHub")
Comment thread doc/articles/signalr.md
|----------|-----------|-------|
| WebAssembly | WebSockets | Requires CORS on the server. The `Microsoft.AspNetCore.SignalR.Client` NuGet package works in Uno WASM without additional configuration. |
| Desktop (Skia) | WebSockets | Works out of the box on Windows, macOS, and Linux. |
| iOS / Android | WebSockets | Works out of the box. Ensure the server URL is reachable from the device or emulator (avoid `localhost`; use the machine's IP or a tunnel such as [dev tunnels](https://learn.microsoft.com/azure/developer/dev-tunnels/overview)). |

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete tutorial rewrite at ae788d74589120b91476fe06a3e33c680e4146d7. The extracted server/Hub compiled and a real loopback SignalR client successfully sent and received the sample broadcast. Two corrections are detailed inline: disconnected sends escape the new async-void handler, and the Visual Studio floor does not support the stated .NET 9 target.

I also reproduced the already-reported directory issue: after the documented cd ChatServer, dotnet run --project ChatServer reports that the project path does not exist. Please fix the existing thread rather than treating this as a second inline report from me. The current platform table has ordinary single leading pipes; I did not count the earlier table warning as a reproduced finding.

Evidence scope: unchanged tutorial server, Hub and ChatPage source with the real SignalR 10.0.0 client; generated UI controls/Page and exception-observing synchronization context were stand-ins. This was not an actual Uno UI, browser/mobile, TLS-trust, production-CORS or deployment run.

Comment thread doc/articles/signalr.md
!string.IsNullOrWhiteSpace(UserTextBox.Text) &&
!string.IsNullOrWhiteSpace(MessageTextBox.Text))
{
await _connection.InvokeAsync(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Handle send failures when the connection is not active

_connection is assigned before StartAsync completes and remains non-null after startup failure or disconnection. The Send button stays enabled, so this branch invokes the hub while disconnected. Running this unchanged handler with the real SignalR client produced InvalidOperationException: The 'InvokeCoreAsync' method cannot be called if the connection is not active both before connection and after StopAsync; the exception escaped through the async-void synchronization context. The connected control successfully broadcast the message and cleared the input.

Gate the send UI/state on an active connection and catch/report invocation failures inside the handler as well, since the connection can drop between a state check and the invocation.

Comment thread doc/articles/signalr.md
- Azure account (to publish SignalR service)
- [.NET 9.0 SDK](https://dotnet.microsoft.com/download) or later
- An Uno Platform app (created via `dotnet new unoapp` or the Uno Platform Visual Studio extension)
- Visual Studio 2022 17.8+, VS Code, or JetBrains Rider

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Align the Visual Studio prerequisite with .NET 9

Visual Studio 17.8 supports targeting .NET 8, not .NET 9. The stated .NET 9 target requires Visual Studio 2022 17.12 or newer; installing the standalone SDK does not add that target support to 17.8. Please raise the IDE floor or explain the CLI-only alternative. Microsoft's SDK/Visual Studio support table documents the distinction.

@Jen-Uno
Jen-Uno marked this pull request as draft November 2, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs] Feedback: SignalR Docs Tutorial/Sample

4 participants