Skip to content

Fix: inject CancellationToken from request context in static commands - #2100

Merged
exyi merged 1 commit into
mainfrom
copilot/fix-static-command-serialization-issue
Aug 28, 2026
Merged

Fix: inject CancellationToken from request context in static commands#2100
exyi merged 1 commit into
mainfrom
copilot/fix-static-command-serialization-issue

Conversation

Copilot AI commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Calling a static command method with a CancellationToken parameter caused a serialization crash (NotSupportedException: Serialization and deserialization of 'System.IntPtr' instances is not supported) because the binding compiler tried to serialize CancellationToken.None as a JSON constant. Since DotVVM bindings have no mechanism to supply a CancellationToken from the client, it should always come from the server's request context.

Changes

  • StaticCommandParameterType – Added CurrentCancellationToken = 5 enum value.
  • StaticCommandMethodTranslator – In CreateExecutionPlan, detect CancellationToken-typed arguments before the constant/default check and emit CurrentCancellationToken plan entries. These are excluded from the client-side JS args array.
  • StaticCommandExecutionPlanSerializer – Serialize CurrentCancellationToken as null (like DefaultValue); deserialize back to a null-arg plan entry.
  • StaticCommandExecutor – Resolve CurrentCancellationToken parameters to context.RequestAborted at invocation time.

Example

[AllowStaticCommand]
public static Task<SessionMetadata> GetMetadataAsync(string sessionId, CancellationToken cancellationToken = default)
    => ...;
<!-- Previously threw NotSupportedException; now works correctly -->
<dot:Button Click="{staticCommand: SessionMetadata = realtimeQuery.GetMetadataAsync(SessionId)}" />

The CancellationToken argument is detected at compile time, stripped from the client payload, and re-injected server-side from IDotvvmRequestContext.RequestAborted.

Copilot AI changed the title [WIP] Fix serialization issue when calling async methods with CancellationToken Fix: inject CancellationToken from request context in static commands Aug 23, 2026
Copilot AI requested a review from tomasherceg August 23, 2026 19:31
@exyi
exyi marked this pull request as ready for review August 28, 2026 12:36
…request context

Co-authored-by: tomasherceg <5599524+tomasherceg@users.noreply.github.com>
Fixed-by: Standa Lukeš
@exyi
exyi force-pushed the copilot/fix-static-command-serialization-issue branch from 1c7ddce to 6941f59 Compare August 28, 2026 13:11
@exyi
exyi merged commit 052814b into main Aug 28, 2026
17 of 19 checks passed
@exyi
exyi deleted the copilot/fix-static-command-serialization-issue branch August 28, 2026 14:02
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.

Calling async methods with CancellationToken using staticCommand fails on serialization

3 participants