Skip to content

feat: .NET 11#339

Open
hhvrc wants to merge 11 commits into
developfrom
feat/dotnet11
Open

feat: .NET 11#339
hhvrc wants to merge 11 commits into
developfrom
feat/dotnet11

Conversation

@hhvrc

@hhvrc hhvrc commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

hhvrc added 3 commits July 17, 2026 20:59
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.
@stage-review

stage-review Bot commented Jul 17, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 7 individual chapters for you:

Title
1 Upgrade project to .NET 11
2 Update CI and Docker environments
3 Implement native Result and Union types
4 Migrate core services to native unions
5 Update API controllers for native unions
6 Update Common and Gateway logic
7 Update tests for native unions
Open in Stage

Chapters generated by Stage for commit e317cb6 on Jul 27, 2026 11:59am UTC.

hhvrc and others added 7 commits July 17, 2026 22:14
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.
@hhvrc
hhvrc marked this pull request as ready for review July 27, 2026 11:56
Copilot AI review requested due to automatic review settings July 27, 2026 11:56
# Conflicts:
#	.github/workflows/ci-build.yml
#	API/Services/Account/AccountService.cs
#	Directory.Packages.props

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

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 to UnionN<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.

Comment thread .github/workflows/codeql.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants