Skip to content

Add source-preserving C# workflow expressions, JSON boundary fixes, and connector validation - #52

Closed
Brian Lam (lambrianmsft) wants to merge 23 commits into
mainfrom
feature/lambrian-csharp-expression
Closed

Brian Lam (lambrianmsft) wants to merge 23 commits into
mainfrom
feature/lambrian-csharp-expression

Conversation

@lambrianmsft

@lambrianmsft Brian Lam (lambrianmsft) commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implement the SDK authoring and definition-generation side of source-preserving C# workflow expressions across built-in actions, managed connectors, and service providers. An SDK-owned Roslyn build tool captures expressions as metadata before compilation; literals remain ordinary JSON and runtime-dependent expressions use native #{...} C#. Refresh generated connectors, preserve their validation through SDK-build injection, and retain workflow JSON at formatting/serialization boundaries instead of prematurely constructing generated CLR models.

This PR is not a new execution-host evaluator or a guarantee of support on every deployed runtime. Runtime evaluation, extension integration, and bundle building have companion changes linked below.

Source-preserving compiler and runtime descriptors

  • src\Build\Microsoft.Azure.Workflows.Sdk.Build: rewrite workflow arguments before ordinary compilation, preserve authored source/overload semantics, analyze bounded source-visible factories, and record native dependencies.
  • src\Expressions\SourceExpression.cs and SourceExpressionConverter.cs: versioned metadata descriptors, explicit workflow bindings, literal/structured JSON values, and native rendering. Remove the legacy expression-tree conversion visitors rather than maintaining a fallback pipeline.
  • Snapshot supported captures at argument-position descriptor construction without executing authoring delegates or custom getters. Keep workflow handles late-bound until definition generation; returned definitions remain snapshots.
  • Update built-in/control/variable/managed/provider expression surfaces to [WorkflowExpression] Func<T> and deferred SDK-owned input construction.
  • Package the compiler and consumer targets under tools/workflow-build and buildTransitive. The runtime remains netstandard2.0; Roslyn/.NET 9 are build-time requirements.
  • Destination/schema handling preserves defaults, nullability, enum wire versus numeric values, path/header/query encoding, JSON intrinsics, dictionary keys, and SDK-owned serialization settings. Dependency manifests and explicit SHA256-pinned host profiles enforce deployment preflight without claiming runtime certification.

JSON materialization and interpolation corrections

The weather response () => $"{weather.Body}" + "something" previously emitted ToObject<CurrentWeather>(); default CLR formatting then printed a model type name. JSON serialization/encoding could also discard properties absent from the model.

  • Recognize JSON consumers using resolved Roslyn operations and parameter symbols. Preserve workflow-backed JSON for default-object interpolation, concatenation, supported formatting overloads, parameterless default ToString(), nested JSON navigation, and approved explicit JSON serialization.
  • Preserve raw JSON before schema-directed JSON/base64 encoding, retaining unknown fields.
  • The JSON formatting bridge uses ToObject<object>(JsonSerializer.Create()): JObject/JArray remain JSON containers, JSON null becomes CLR null, overload selection stays object-based, and ambient serializer defaults are not consulted.
  • Preserve typed behavior for numeric/date formatting, custom ToString()/IFormattable, authored/captured objects, typed method calls, and collection operations. Generic bindings resolve the formatting contract at definition construction without invoking delegates.
  • Avoid unnecessary generated-model runtime dependency records for JSON-only consumers. Actual typed operations and SDK helper calls still need their declared host dependencies.
  • Protect binding-generated qualified type names inside interpolation holes so global:: is not parsed as a format separator.
  • Add 45 behavioral JSON-boundary cases, interpolation regressions, exact Msnweather deployment/route tests, and serialization-test-cases.md. Assertions check evaluated payloads, unknown fields, nulls, reads, laziness, and typed negative controls, not merely source strings.

Example, before JSON escaping:

// Authoring
responseBody: () => $"{weather.Body}" + "something"
#{$"{body("Weather").ToObject<object>(global::Newtonsoft.Json.JsonSerializer.Create())}" + "something"}

Literals and compiler-known constants remain data; runtime operations preserve native C#. Recognized direct workflow/property references remain JSON-native.

Connector regeneration and validation

  • Refresh 1,573 generated managed/provider files from the Logic Apps Bundle CodefulSdkGenerator; retain CardsforpowerappsExtensions.cs because no replacement was generated. Relative to the PR base, add 227 managed files and 3 provider files; the catalog contains 34 regenerated provider files in total.
  • Preserve public signatures, wire names, historical empty-object-body omission, and narrowly scoped default/encoding compatibility. Unsupported/internal/deprecated operations may disappear during refresh; catalog coverage is not a claim that all historical operations remain available.
  • Remove 65,338 explicit validation statements from 1,282 generated files while retaining compiled argument validation through ConnectorValidationTransformer.cs and ConnectorValidation.targets.
  • Inject validation into intermediate copies at method entry, in parameter order, using original names and signature-derived requiredness. This protects direct, reflection, method-group, and precompiled callers, independently of consumer rewriting.
  • Reject unsupported/incomplete transformations and old generated sources still emitting explicit validation. Package creation, including pack --no-build, verifies the successful injection-build receipt.
  • tests\GeneratedConnectorParity compares inventories/APIs/implementation syntax and compiles external generated sources through the actual SDK build.

Complete local candidate preparation and durable integration guidance

  • tests\ExtensionE2E\New-ExtensionCandidate.ps1 builds the complete versioned SDK nupkg and invokes the companion Logic Apps Bundle source builder, or imports an existing verified ZIP/producer receipt.
  • Validate required archive payloads, package identities, version/hash consistency, producer provenance, and copy integrity; generate a hash-pinned candidate.json. Use fresh immutable roots rather than overwriting existing candidates or installed caches.
  • Optionally hand the manifest to the LogicAppsUX candidate runner. Document bundle/SDK/extension prerequisites, complete webview packaging, Windows environment requirements, private F5 staging, and distinct installation/build/debugger/execution acceptance gates.
  • Add a packaged SourceExpressionE2E mode selecting E2ESdkPackageVersion; prohibit mixing it with repository compiler imports or comparison assemblies.
  • Use “Logic Apps Bundle” terminology in README prose while preserving existing script parameters/paths such as -BpmRepository.
  • Add root AGENTS.md and a README discovery link to the central three-repository runbook in tests\ExtensionE2E\README.md. Capture supplied checkout/tool inputs, SDK9 versus bundle10/VS18 prerequisites, exact dependency-generator npm ci, source-preserving handoff, JSON/Swagger regressions, owned-process/debugger evidence, authorization, privacy, and known unsupported cases.
  • Document the companion UX portable copy/retarget/guarded-launch workflow: installed sealed roots, original-source fingerprints distinct from iterative destination edits, package/feed retargeting, active-profile refusal, isolated environment, and manual metadata/sign-in. Explicitly distinguish the built product --extension from the read-only dependency source --extensions.
  • Installation must finish before copying a workspace beneath the candidate root. Document the product owner-marker schema, exact manifest path, and manifest-byte SHA256 preflight used by the companion launcher; an envelope receipt alone is not proof of installation. Keep the workspace inside the installed candidate to satisfy product build/F5 containment. This preflight does not replace payload integrity or runtime acceptance.
  • These reusable scripts ship in Isolated SDK candidate testing infra, Windows F5 host fixes, and native C# Swagger path inference fix lambrianmsft/LogicAppsUX#22, not this SDK PR. Historical private profiles, selected candidate binaries, and session-specific receipts remain local evidence and are not prerequisites for the documented workflow.

Validation

Local code rerun before publishing commit fd99e1f:

Check Result
Source-expression suite 983 passed, 0 failed/skipped
C# expression suite 108 passed, 0 failed/skipped
Expression suite 8 passed, 0 failed/skipped
Candidate-kit archive/producer/runner guards 18 passed; synthetic/stub interfaces, not VS Code execution

Documentation follow-ups through efbdf96 change no runtime/compiler code. All 11 PowerShell examples parse, local Markdown links resolve, and git diff --check passes. Documented manual-launch commands were not executed as a fresh editor/host/workflow acceptance run.

Additional recorded evidence:

  • Complete 1.0.0-e2e.ff748b0.jsonboundary1 package was built from the changed source; library/compiler hashes matched the isolated build and restored candidate assets. The copied user project built with 0 warnings/errors, and provider definition serialization emitted the JSON-preserving weather expression without a CurrentWeather dependency. This did not start a host or invoke a connector.
  • Corrected weather interpolation executed on the shipped .NET 8 runtime engine with populated JSON and JSON null, cached and uncached, without an SDK model-reference approval requirement. This is a bounded engine proof, not a live managed-weather workflow or UI/debugger run.
  • Historical injection migration: 22 actual MSBuild checks; 1,573/1,573 generated files byte-identical; 162/162 baseline/injected definition exports byte-identical; 37 harness self-tests passed. Hosted injection comparison passed 142/162 in both variants with identical 20 failures. This establishes unchanged injection outcomes on that pinned runtime, not universal runtime support.

Compatibility and known limits

  • Raw/untransformed delegates and expression trees are unsupported; design-time builds explicitly defer transformation. Validation-free generated output requires the injection-enabled SDK build.
  • JSON consumer handling is bounded, not blanket removal of ToObject<T>(). Arbitrary typed methods, unsupported navigation, custom serializers/overloads, and application-defined runtime types retain their existing typing/deployment requirements.
  • Historical full-host comparisons include unsupported custom-type and URI-response cases. The latest JSON-boundary/packaged-engine checks do not establish that the full runtime suite is green.
  • A full solution/sample build has existing RecruitmentWorkflow.cs calls to missing CommondataserviceActions.ListRecords; it is not counted as passing.
  • No production/cloud execution, full refreshed extension UI, or debugger-attach acceptance is claimed by the compiler/serialization and candidate-preparation checks.

Related work

  • Logic Apps Bundle connector/runtime/tooling PR 17341699: companion branch for compatible connector generation and runtime/bundle tooling. Its own PR describes the actual runtime diff and validation; its README owns source-build bootstrap.
  • lambrianmsft/LogicAppsUX#22: isolated candidate installation/F5 setup, portable manual candidate-switch tooling, Windows process/environment repairs, and bounded native C# Swagger route inference/input initialization. Its run-candidate-e2e.md owns the extension runner/launcher interfaces.
  • Andrew's output-normalization PR 17363358: separate execution-host normalization work; do not infer it from passing SDK descriptor tests.

Rohitha Hewawasam and others added 16 commits July 4, 2026 21:06
Introduce a runtime evaluator for serialized C# workflow expressions plus a
static reference extractor, alongside characterization/goal test suites.

- src/...ExpressionEvaluation: netstandard2.0 NuGet package
  - RoslynWorkflowExpressionEvaluator (compile + cache + run via Roslyn)
  - WorkflowExpressionGlobals (free-function host: outputs/body/trigger/etc.)
  - WorkflowExpressionReferenceExtractor (static trigger/action/variable/
    agent-parameter reference inference to drive async pre-fetch)
- tests/...ExpressionTests: LA ExpressionConverter characterization tests
- tests/...CSharpExpressionTests: 82 C# converter goal tests (red by design)
- tests/...ExpressionEvaluationTests: 85 evaluator + extractor tests (green)
- Core SDK csproj: InternalsVisibleTo + exclude nested evaluator from glob
- Solution: add new projects

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tion

Merge feature branch from fork: Add C# expression evaluation library, reference extractor, and tests
…sion-evaluation

# Conflicts:
#	Microsoft.Azure.Workflows.Sdk.sln
Route built-in actions through the hybrid converter, preserve template-compatible expressions, add serialization parity behavior, and expand converter coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Update all generated managed connector inputs to use CSharpExpressionConverter while retaining native Logic Apps expressions when C# execution is unnecessary.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Route upstream generated service-provider parameters through CSharpExpressionConverter and cover template-safe versus native C# output.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Integrate SDK build-time expression transformation, generated connector descriptors, schema-aware serialization, and deployment validation. Add approved-catalog, package, IDE, and runtime verification with explicit remaining host/platform gates.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… limitation

Preserve the original workflow contracts, add nested JSON and Response controls, and retain precise failure diagnostics. CI provisioning is not included.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep executable compiler, package, host and E2E regressions. Remove historical ledgers, copied logs and evidence-only checks, drop stale fixture references, and mark generated connectors for collapsed review. Historical files remain available in the preceding commit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use #{...} across generated connectors, preserve literal and JSON-reference semantics, and expand isolated service-provider coverage. Remove retired expression-tree implementations and migrate applicable tests to source-compiled authoring.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SourceExpression.Validate(bodystartDateTime, nameof(bodystartDateTime), required: true);
SourceExpression.Validate(bodyendDateTime, nameof(bodyendDateTime), required: true);
SourceExpression.Validate(bodyname, nameof(bodyname), required: true);
SourceExpression.Validate(bodydescription, nameof(bodydescription), required: true);

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.

copying comment from the CodefulSdkGenerator pr: why are the new SourceExpression.Validate and BuildSourceInput delegate needed? I know this differs from the interceptors implementation but that one required minimal changes to generated connectors (just [WorkflowExpression] attribute) and wondering if we can accomplish the same here

Integrate the full managed and service-provider output from BPM e27dd53fc33215bb52e7962194b19768e4759959 (PR 17341699), including 230 new generated files. Preserve Cardsforpowerapps because no replacement was generated. Include connector regression coverage, current API callers, parity tooling, and generation guidance.

The catalog retains 22 configured skips and 104 connector-level failures. Existing unsupported-operation omissions, including managed multipart operations, are not claimed fixed.

Validated the exact staged tree independently of unstaged runtime/compiler refactoring: 108 CSharpExpression, 789 SourceExpression, and 8 Expression tests pass; E2E project builds.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Normalize legacy descriptor metadata once, remove redundant template-segment construction, share enum/numeric wire policy, and separate schema source generation from runtime serialization. Replace ambient dependency collection with an explicit per-transform collector and clarify factory, schema, deployment, and build-tool responsibilities.

Include solution integration, documentation, and regression coverage for interpolation, descriptor compatibility, dependency isolation, factory destinations, and serializer policy. All 921 expression tests pass and the E2E authoring project builds.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move generated connector validation into SDK-only Roslyn build injection while preserving method-entry validation for all callers. Share build manifest tasks, enforce package build receipts, and add contract, transformer, build, and package coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lambrianmsft Brian Lam (lambrianmsft) changed the title Feature/lambrian csharp expression Add source-preserving C# workflow expressions and build-time connector validation Oct 1, 2026
Add behavioral boundary regressions, typed interpolation safeguards, complete SDK/bundle candidate preparation, packaged E2E selection, and updated documentation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lambrianmsft Brian Lam (lambrianmsft) changed the title Add source-preserving C# workflow expressions and build-time connector validation Add source-preserving C# workflow expressions, JSON boundary fixes, and connector validation Oct 5, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@andrew-eldridge

Copy link
Copy Markdown
Contributor

replaced by #58

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.

2 participants