From f5da2c486adff49b21b9bce1a2f86aeafe10dcb8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:00:35 +0000 Subject: [PATCH 1/2] Initial plan From 940e88679013a9f52d76636098207e63b1a1d61e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:10:44 +0000 Subject: [PATCH 2/2] Fix XUnitWrapperGenerator generating invalid code for Theory MemberData with conditional attributes When a Theory test uses MemberDataAttribute and is also decorated with conditional skip attributes (SkipOnPlatform, SkipOnCoreClr, etc.), the generator wraps the MemberDataTest inside a ConditionalTest. The ConditionalTest.GenerateTestExecution() puts the foreach loop (from MemberDataTest) inside the if-condition block, but the else block uses MemberDataTest.TestNameExpression which was previously copied from the inner BasicTestMethod's TestNameExpression. That expression contains a reference to the testArguments loop variable (e.g., testArguments[0], string.Join(",", testArguments)), causing CS0103 since testArguments is only in scope inside the foreach loop. Fix: Change MemberDataTest.TestNameExpression to use a static literal string "alias::Type.Method(...)" that doesn't reference any loop variables. The inner BasicTestMethod.TestNameExpression still references testArguments for per-iteration reporting inside the foreach loop. Fixes: error CS0103: The name 'testArguments' does not exist in the current context Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ff0bc935-d962-4daf-891b-5592aab629f4 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com> --- src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs b/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs index 08702f531e39c7..3430dfce259b3d 100644 --- a/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs +++ b/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs @@ -295,9 +295,11 @@ public MemberDataTest(ISymbol referencedMember, string externAlias, string argumentLoopVarIdentifier) { - TestNameExpression = innerTest.TestNameExpression; Method = innerTest.Method; ContainingType = innerTest.ContainingType; + // Use a static expression that doesn't reference the loop variable since it may be used + // outside the foreach loop scope (e.g., in a ConditionalTest's else branch). + TestNameExpression = $"\"{externAlias}::{ContainingType}.{Method}(...)\""; DisplayNameForFiltering = $"{ContainingType}.{Method}(...)"; _innerTest = innerTest;