Skip to content

Harden typed task parameter infrastructure - #7

Draft
OvesN wants to merge 2 commits into
mainfrom
dev/veronikao/typed-parameter-infrastructure-fixes
Draft

Harden typed task parameter infrastructure#7
OvesN wants to merge 2 commits into
mainfrom
dev/veronikao/typed-parameter-infrastructure-fixes

Conversation

@OvesN

@OvesN OvesN commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Fixes #

Context

These issues were found while migrating real in-box tasks to typed parameters in OvesN/msbuild#6. Direct task tests passed, but real MSBuild binding, malformed inputs, logging, event forwarding, and binlog replay exposed infrastructure gaps.

Changes Made

  • Malformed typed-item paths could escape as unhandled exceptions.
    TaskItem<T> derives path values from FullPath; malformed values could throw InvalidOperationException, bypassing normal parameter-binding error handling. The constructor now converts this to ArgumentException, allowing MSBuild to report MSB4030.

    Real-world reproduction:

    <GetFileHash Files="bad%00path" />

    Before the fix, binding ITaskItem<AbsolutePath>[] could terminate the node with an unhandled exception while evaluating FullPath. After the fix, the project receives:

    MSB4030: "bad path" is an invalid value for the "Files" parameter of the "GetFileHash" task.
    
  • Logging of AbsolutePath task parameters could crash or inflate paths.
    ItemGroupLoggingHelper treated AbsolutePath as an arbitrary value type and called Convert.ChangeType, which throws because AbsolutePath is not IConvertible. Now we log absolute path correctly, using originally passed path in logs AbsolutePath.OriginalValue.

    Real-world reproduction:

    <VerifyFileHash File="input.txt"
                    Hash="3306EA2566F10A3C4071D8BADFB92A83D4F1D428555B4936D21C10F4F775B351" />

    With task-input logging enabled, MSBuild attempted to format the bound AbsolutePath and failed with:

    InvalidCastException: Object must implement IConvertible.
    MSB4166: Child node exited prematurely.
    

    The fixed output remains relative:

    Task Parameter:File=input.txt
    
  • Forwarded task-parameter events lost relative path values.
    TaskParameterEventArgs serialized AbsolutePath through ToString(), replacing a value such as input.txt with its absolute form. Forwarding now serializes OriginalValue.

    Real-world example:

    Originating node: Task Parameter:File=input.txt
    Receiving node:   Task Parameter:File=C:\repo\input.txt
    

    A distributed logger could therefore observe a different value depending on which node produced the event. Forwarded events now retain input.txt.

  • Binlog task-parameter serialization lost relative path values.
    BuildEventArgsWriter had the same ToString() behavior, so replayed binlogs differed from live output. Binlog serialization now preserves OriginalValue.

    Real-world example:

    Live build:      Task Parameter:File=input.txt
    Replayed binlog: Task Parameter:File=C:\repo\input.txt
    

    The live and replayed event streams now contain the same relative value.

Testing

Each fix has a dedicated regression test:

  • FromITaskItem_InvalidPath_ThrowsArgumentException
  • AbsolutePathTaskParameterTextUsesOriginalValue
  • TaskParameterEventForwardingPreservesAbsolutePathOriginalValue
  • BinaryLogSerializationPreservesAbsolutePathOriginalValue

All dedicated tests pass on net11.0 and net472. The full Debug build also succeeds.

Notes

This PR contains only typed-parameter infrastructure fixes. The task migrations and user documentation are in the stacked PR OvesN/msbuild#6.

Add dedicated regression coverage for malformed typed items, AOT-safe path factories, live parameter logging, event forwarding, and binlog serialization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant