feat: .NET 11#339
Open
hhvrc wants to merge 16 commits into
Open
Conversation
Prerequisite for adopting C# union types (discriminated unions), which ship as a preview language feature in .NET 11.
Converts every OneOf<T0,...>/OneOf.Types usage to C# union declarations (union keyword, LangVersion=preview), the structural-union language feature shipped in .NET 11 Preview 2. - Common/Results/Unions.cs: generic Union2<T0,T1>..Union8<..> declarations replacing OneOf<T0,...T7>. - Common/Results/CommonResultCases.cs: Success, Success<T>, NotFound, Error, Error<T>, None replacing OneOf.Types. - Rewrote every .Match/.Switch/.TryPickTx/.AsTx/.IsTx call site to switch expressions/statements and `is` patterns, since union declarations only expose a Value property plus constructors (no generated helper methods). - Removed the OneOf package reference from Common.csproj and Directory.Packages.props. Note: OpenShock.Common.Results.NotFound/Unauthorized share a name with inherited ControllerBase.NotFound()/.Unauthorized() methods, so a few controller files alias the namespace (`using Results = ...`) to disambiguate bare switch-pattern usage.
Enables the runtime-async feature switch solution-wide so async methods suspend/resume via the runtime instead of compiler-generated state machines: cleaner stack traces, better debuggability, lower overhead. No source changes needed - this only affects codegen.
|
Ready to review this PR? Stage has broken it down into 8 individual chapters for you: Chapters generated by Stage for commit 3ded5f8 on Jul 27, 2026 2:45pm UTC. |
The generic mcr.microsoft.com/dotnet/sdk:11.0-alpine tag doesn't exist yet since .NET 11 is still preview; MCR only publishes preview-qualified tags. Also the runtime stages were still on dotnet/aspnet:10.0-alpine while the apps target net11.0, a mismatch that builds but crashes at container startup. Also fix .dockerignore's dev/ pattern to Dev/ to match the actual (case-sensitive) directory name, so local Postgres data doesn't leak into the build context.
# Conflicts: # .github/workflows/ci-build.yml # API/Services/Account/AccountService.cs # Directory.Packages.props
Contributor
There was a problem hiding this comment.
Pull request overview
Upgrades the solution to .NET 11 (preview) and replaces the OneOf dependency with new C# union types + shared result case types, updating call sites across API, Common, Cron, and LiveControlGateway. Also updates Docker images and CI/workflows to build against .NET 11.
Changes:
- Migrate
OneOf<T...>usages toUnionN<T...>and introduce shared result case types (Success,NotFound,Error, etc.). - Update solution-wide target framework to
net11.0, enable C#preview, and pin .NET 11 preview SDK/container images. - Refresh CI/workflows and Dockerfiles to use .NET 11.
Reviewed changes
Copilot reviewed 67 out of 67 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| LiveControlGateway/Websocket/FlatbufferWebSocketUtils.cs | Switch flatbuffer receive helper from OneOf to Union3. |
| LiveControlGateway/Websocket/FlatbuffersWebsocketBaseController.cs | Replace OneOf.Match receive handling with switch over Union3. |
| LiveControlGateway/LifetimeManager/HubLifetimeManager.cs | Update lifetime manager APIs to Union2/Union3 and adjust marker docs. |
| LiveControlGateway/LifetimeManager/HubLifetime.cs | Convert key methods to Union2/Union3 return types. |
| LiveControlGateway/Controllers/LiveControlController.cs | Replace OneOf patterns with union switches/pattern matching in websocket flow. |
| LiveControlGateway/Controllers/HubControllerBase.cs | Update connection precondition result type + switch handling for union cases. |
| global.json | Pin repo SDK to .NET 11 preview and allow prerelease resolution. |
| docker/LiveControlGateway.Dockerfile | Update runtime base image to .NET 11 preview (alpine3.24). |
| docker/Cron.Dockerfile | Update runtime base image to .NET 11 preview (alpine3.24). |
| docker/Base.Dockerfile | Update SDK build stage image to .NET 11 preview (alpine3.24). |
| docker/API.Dockerfile | Update runtime base image to .NET 11 preview (alpine3.24). |
| Directory.Packages.props | Remove OneOf, bump key packages, and add a scoped crypto XML patch reference. |
| Directory.Build.props | Target net11.0, enable C# preview, and enable runtime-native async feature. |
| Cron/Services/Email/EmailTemplate.cs | Convert parsing helpers to Union2 and update callers. |
| Common/Websocket/WebsockBaseController.cs | Update websocket precondition to Union2 and adjust handling. |
| Common/Validation/UsernameValidator.cs | Change validator result to Union2<Success, UsernameError>. |
| Common/Utils/JsonWebSocketUtils.cs | Change receive helper return type to Union3. |
| Common/Services/Webhook/WebhookService.cs | Update service API to Union2/Union4. |
| Common/Services/Webhook/IWebhookService.cs | Update interface return types to Union2/Union4. |
| Common/Services/IControlSender.cs | Update control sender interface return type to Union4. |
| Common/Services/ControlSender.cs | Update implementation to Union4. |
| Common/Services/Configuration/IConfigurationService.cs | Replace OneOf with Union3/Union4 across configuration API. |
| Common/Services/Configuration/ConfigurationService.cs | Update implementation signatures/returns to unions. |
| Common/Results/Unions.cs | Add Union2..Union8 type declarations (structural unions). |
| Common/Results/CommonResultCases.cs | Add shared union case types (Success/NotFound/Error/None). |
| Common/Hubs/UserHub.cs | Replace TryPickT* with pattern matching on union auth reference. |
| Common/Hubs/PublicShareHub.cs | Replace TryPickT* with pattern matching on union auth reference. |
| Common/DataAnnotations/UsernameAttribute.cs | Update attribute validation handling to switch over union result. |
| Common/Common.csproj | Remove OneOf package reference. |
| Common/Authentication/Services/UserReferenceService.cs | Change AuthReference to Union3<LoginSession, ApiToken, None>. |
| Common/Authentication/ControllerBase/AuthenticatedSessionControllerBase.cs | Replace Match with union switch for permission evaluation. |
| Common/Authentication/Attributes/TokenPermissionAttribute.cs | Replace Match with union switch for auth validation. |
| Common.Tests/Validation/UsernameValidatorTests.cs | Update tests to assert union cases via pattern matching. |
| API/Services/Turnstile/ICloudflareTurnstileService.cs | Update turnstile service contract to Union2. |
| API/Services/Turnstile/CloudflareTurnstileService.cs | Update implementation signature to Union2. |
| API/Services/Account/IAccountService.cs | Replace OneOf with UnionN across account service contract. |
| API/Services/Account/AccountService.cs | Update implementation to return/use union types. |
| API/Controller/Tokens/ReportTokens.cs | Update turnstile result handling to union pattern matching. |
| API/Controller/Tokens/GetTokenSelf.cs | Replace TryPickT* with pattern matching for token extraction. |
| API/Controller/Shockers/SendControl.cs | Replace Match with union switch for control responses. |
| API/Controller/Sessions/SessionSelf.cs | Replace TryPickT* with pattern matching for session extraction. |
| API/Controller/OAuth/SignupGetData.cs | Convert OAuth flow validation to Union2 and update handling. |
| API/Controller/OAuth/SignupFinalize.cs | Convert OAuth flow validation + create-account result handling to unions. |
| API/Controller/OAuth/HandOff.cs | Convert OAuth flow validation handling to unions. |
| API/Controller/OAuth/_ApiController.cs | Replace OAuth validation return type with Union2. |
| API/Controller/Devices/DevicesController.cs | Replace gateway resolve result with Union2 and update call sites. |
| API/Controller/Admin/WebhookAdd.cs | Replace Match with union switch expression. |
| API/Controller/Admin/ReactivateUser.cs | Replace Match with union switch and disambiguate case types. |
| API/Controller/Admin/DeleteUser.cs | Replace Match with union switch and disambiguate case types. |
| API/Controller/Admin/DeactivateUser.cs | Replace Match with union switch and disambiguate case types. |
| API/Controller/Admin/Configuration.cs | Replace Match with union switch expressions for config endpoints. |
| API/Controller/Account/VerifyEmail.cs | Replace Match with union switch expression for verify result. |
| API/Controller/Account/SignupV2.cs | Replace Match with union switch expression for account creation. |
| API/Controller/Account/PasswordResetComplete.cs | Replace Match with union switch expression for reset completion. |
| API/Controller/Account/PasswordResetCheckValid.cs | Replace Match with union switch expression for reset validity check. |
| API/Controller/Account/LoginV2.cs | Replace Match with union switch expression for credential errors. |
| API/Controller/Account/CheckUsername.cs | Replace Match with union switch expression for username availability. |
| API/Controller/Account/Authenticated/Deactivate.cs | Replace Match with union switch expression for deactivation result. |
| API/Controller/Account/Authenticated/ChangeUsername.cs | Replace Match with union switch expression for username change result. |
| API/Controller/Account/Authenticated/ChangePassword.cs | Replace Match with union switch expression for password change result. |
| API/Controller/Account/Authenticated/ChangeEmail.cs | Replace Match with union switch expression for email change result. |
| API/Controller/Account/_Turnstile.cs | Update turnstile result handling to union pattern matching. |
| .github/workflows/update-cloudflare-proxies.yml | Add DOTNET_VERSION env and reorder workflow name block. |
| .github/workflows/codeql.yml | Update DOTNET_VERSION for CodeQL build. |
| .github/workflows/ci-tag.yml | Update DOTNET_VERSION to .NET 11. |
| .github/workflows/ci-build.yml | Update DOTNET_VERSION to .NET 11. |
| .dockerignore | Update ignored dev directory casing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Matches the 11.0.x format used in ci-build.yml and ci-tag.yml.
These files already alias the namespace as `Results`; qualify the bare Success/NotFound references that relied on the plain using instead of importing the namespace twice.
…appers Convert union case marker types from readonly structs to sealed classes/records so they're stored as plain references in the union's internal object? slot instead of being boxed, and drop Success<T>/Error<T> wrappers where the payload type can serve as the case directly. Also consolidates duplicate marker types (DeviceNotFound, ShockerNotFoundOrNoAccess, WebsocketClosure) into shared ones and replaces ConfigurationService's Union3/Union4-based getters with a dedicated ConfigGetResult<T>.
…ern matching Parse errors were unwrapped via an unchecked (string)result.Value! cast on the Union2 case, bypassing the union's type safety. Introduce a dedicated TemplateParseError case type and switch on it directly. Keep the internal parse logic non-throwing (returns the union) and confine the throw to the public ParseFromFileOrThrow convenience wrapper used at startup.
…le case TryVerifyEmailAsync's success case was renamed to the VerifyEmailSuccess record, but the controller's switch still matched the old tuple-wrapped Success<(Guid, string, string)> type, breaking the Release build (CS8121) and failing both the ci-build and CodeQL workflows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.