Skip to content

CloneWithUpdatedSource mutates this instead of the returned clone #9573

Closed

Description

Summary

TestMethod.CloneWithUpdatedSource(string source) (and by extension UnitTestElement.CloneWithUpdatedSource) in src/Adapter/MSTestAdapter.PlatformServices/ObjectModel assigns the new source (and clears MethodInfo) on this rather than on the returned clone:

internal TestMethod CloneWithUpdatedSource(string source)
{
    var clone = (TestMethod)MemberwiseClone();
    AssemblyName = source;   // mutates `this`, not `clone`
    MethodInfo = null;       // mutates `this`, not `clone`
    return clone;            // clone still carries the OLD source/MethodInfo
}

So the returned "updated-source" clone actually keeps the old source, while the original (shared) element is mutated as a side effect. This is a latent bug that today's call order happens to tolerate (the shared element is re-read on subsequent calls), and the filter path is unaffected because the discovered test id is filename-based (source-path-independent).

Context

Phase 4 of the platform-agnostic effort (making MSTestAdapter.PlatformServices VSTest-object-model-free) needs correct element-based source resolution for the deployment path (see #6713 — the executed assembly must load from the deployment directory). Rather than change the shared primitive inside a strict no-behavior-change refactor, Phase 4 introduces a new, correct source-update method for the neutral engine path and leaves the existing buggy CloneWithUpdatedSource untouched for the ToTestCase/filter bridge callers, with a code comment referencing this issue.

Follow-up

Unify the two clone methods: fix CloneWithUpdatedSource to assign on the clone (and drop MethodInfo on the clone), migrate the remaining bridge callers, and remove the now-redundant method — verifying the deployment + cross-process suites stay green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions