Repository navigation
Conversation
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
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23992/docs/index.html |
There was a problem hiding this comment.
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.csguidance withProgram.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.
|
|
||
| 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: | ||
|
|
| ## 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: |
| 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(); | ||
| }); | ||
| ``` | ||
| }); |
| > [!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. |
| | 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. | |
| private async void ChatPage_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| _connection = new HubConnectionBuilder() | ||
| .WithUrl("https://localhost:5001/chatHub") |
|
|
||
| ```csharp | ||
| var connection = new HubConnectionBuilder() | ||
| .WithUrl("https://localhost:5001/chatHub") |
| |----------|-----------|-------| | ||
| | 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
left a comment
There was a problem hiding this comment.
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.
| !string.IsNullOrWhiteSpace(UserTextBox.Text) && | ||
| !string.IsNullOrWhiteSpace(MessageTextBox.Text)) | ||
| { | ||
| await _connection.InvokeAsync( |
There was a problem hiding this comment.
[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.
| - 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 |
There was a problem hiding this comment.
[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.
What this PR does
Modernizes the SignalR integration tutorial (
doc/articles/signalr.md):Startup.cs/ConfigureServicespattern with the currentProgram.csminimal-hosting model.dotnet new web+dotnet add package Microsoft.AspNetCore.SignalR.ClientCLI flow, structured into clear "Create the server" / "Add SignalR to the Uno client" steps.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