Skip to content

Commit 20e1314

Browse files
committed
Fix deployment regression
1 parent fb87bc2 commit 20e1314

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Adapter/MSTestAdapter.PlatformServices/Extensions/TestCaseExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string
7272
{
7373
if (testCase.LocalExtensionData is UnitTestElement unitTestElement)
7474
{
75-
return unitTestElement;
75+
// If the requested source is different, clone it with updated source.
76+
// This can happen when there are deployment items in tests.
77+
// In this case, the source would be the path of the deployment directory.
78+
// If we don't return UnitTestElement with the correct path to deployment directory, we will
79+
// end up trying to load the test assembly twice in the same appdomain, once with the default context and once in a LoadFrom context.
80+
// See https://github.com/microsoft/testfx/issues/6713
81+
return unitTestElement.TestMethod.AssemblyName != source
82+
? unitTestElement.CloneWithUpdatedSource(source)
83+
: unitTestElement;
7684
}
7785

7886
string? testClassName = testCase.GetPropertyValue(EngineConstants.TestClassNameProperty) as string;

src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ public string? DeclaringClassFullName
165165
internal string DisplayName { get; set; }
166166

167167
internal TestMethod Clone() => (TestMethod)MemberwiseClone();
168+
169+
internal TestMethod CloneWithUpdatedSource(string source)
170+
{
171+
var clone = (TestMethod)MemberwiseClone();
172+
AssemblyName = source;
173+
return clone;
174+
}
168175
}

src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/UnitTestElement.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ internal UnitTestElement Clone()
9292
return clone;
9393
}
9494

95+
internal UnitTestElement CloneWithUpdatedSource(string source)
96+
{
97+
var clone = (UnitTestElement)MemberwiseClone();
98+
clone.TestMethod = TestMethod.CloneWithUpdatedSource(source);
99+
return clone;
100+
}
101+
95102
/// <summary>
96103
/// Convert the UnitTestElement instance to an Object Model testCase instance.
97104
/// </summary>

0 commit comments

Comments
 (0)