Skip to content

Fix issue with callback invocation target resolution#14785

Merged
davidfowl merged 1 commit intorelease/13.2from
fix-polyglot-target-invocation
Mar 3, 2026
Merged

Fix issue with callback invocation target resolution#14785
davidfowl merged 1 commit intorelease/13.2from
fix-polyglot-target-invocation

Conversation

@IEvangelist
Copy link
Member

Description

Enhance capability invocation by resolving builder to resource for properties and methods

Contributes to #14772

Fixes this issue:

Executing command 'clear-database'.
 Error executing command 'clear-database'.
StreamJsonRpc.RemoteInvocationException: Request invokeCallback failed with message: Callback execution failed: Object type Aspire.Hosting.ApplicationModel.PostgresDatabaseResource does not match target type Aspire.Hosting.DistributedApplicationResourceBuilder`1[Aspire.Hosting.ApplicationModel.PostgresDatabaseResource].
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at Aspire.Hosting.RemoteHost.JsonRpcCallbackInvoker.InvokeAsync[TResult](String callbackId, JsonNode args, CancellationToken cancellationToken)
   at Aspire.Hosting.RemoteHost.Ats.AtsCallbackProxyFactory.InvokeAsyncResult[T](String callbackId, JsonObject args, CancellationToken cancellationToken)
   at Aspire.Hosting.ApplicationModel.ResourceCommandService.ExecuteCommandCoreAsync(String resourceId, IResource resource, String commandName, CancellationToken cancellationToken) in D:\GitHub\aspire\src\Aspire.Hosting\ApplicationModel\ResourceCommandService.cs:line 138

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings February 27, 2026 22:18
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14785

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14785"

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit dd4e267:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ❌ Upload failed
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22628797900

Copilot AI review requested due to automatic review settings March 2, 2026 21:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the ATS (Aspire Type System) capability invocation infrastructure where callbacks targeting properties or methods declared on a resource type T would fail when the handle registry contained an IResourceBuilder<T> instead of the resource directly. This happens because AtsCapabilityScanner.MapToAtsTypeId maps both IResourceBuilder<T> and T to the same ATS type ID, so handles of either type can end up being registered under the resource's type ID.

Changes:

  • Added ResolveContextTarget private helper in CapabilityDispatcher to unwrap an IResourceBuilder<T> to its .Resource when the member being invoked is declared on the resource type T
  • Applied this unwrapping consistently in RegisterContextTypeProperty (getter and setter) and RegisterContextTypeMethod
  • Added six new unit tests covering the builder-to-resource resolution scenarios, including regression tests for direct resource handles and inherited properties

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Aspire.Hosting.RemoteHost/Ats/CapabilityDispatcher.cs Adds ResolveContextTarget method and applies it to property getter, setter, and instance method dispatch paths
tests/Aspire.Hosting.RemoteHost.Tests/CapabilityDispatcherTests.cs Adds test helper classes (TestResourceBuilder<T>, TestResourceWithProperties, TestResourceWithMethods) and six new [Fact] tests covering the fix

@davidfowl
Copy link
Contributor

@IEvangelist wrong base branch

@IEvangelist IEvangelist changed the base branch from main to release/13.2 March 3, 2026 14:01
@IEvangelist IEvangelist force-pushed the fix-polyglot-target-invocation branch from ed55c1a to dd4e267 Compare March 3, 2026 14:59
@IEvangelist
Copy link
Member Author

@IEvangelist wrong base branch

@davidfowl - fixed, targeting correct branch now.

@davidfowl davidfowl merged commit a96a744 into release/13.2 Mar 3, 2026
757 of 761 checks passed
@davidfowl davidfowl deleted the fix-polyglot-target-invocation branch March 3, 2026 23:01
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 3, 2026
Copilot AI pushed a commit that referenced this pull request Mar 10, 2026
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.

4 participants