Skip to content

VS Test Explorer NUnit error: "TestPlatformFormatException: Filter string ... includes unrecognized escape sequence" #1241

@Evangelink

Description

@Evangelink

Describe the bug

When running a parametrized NUnit test where the parameter is the " string, the following error appears in the Test Explorer output (dotnet test works fine):

[17/02/2025 4:25:21.638 pm] [Error] Process: TestProject3\TestProject3\bin\Debug\net8.0\TestProject3.dll, Exception: StreamJsonRpc.RemoteInvocationException: Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.TestPlatformFormatException: Filter string 'TestProject3.Test1.TestMethod1\("\\\"\)' includes unrecognized escape sequence.
   at Microsoft.Testing.Extensions.VSTestBridge.ObjectModel.ContextAdapterBase.GetTestCaseFilter(IEnumerable`1 supportedProperties, Func`2 propertyProvider) in /_/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ContextAdapterBase.cs:line 43
   at NUnit.VisualStudio.TestAdapter.VsTestFilter.get_TfsTestCaseFilterExpression() in C:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\VsTestFilter.cs:line 89
   at NUnit.VisualStudio.TestAdapter.VsTestFilter.get_IsEmpty() in C:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\VsTestFilter.cs:line 91
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.InitializeForExecution(IRunContext runContext, IFrameworkHandle frameworkHandle) in C:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 282
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in C:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 120
   at NUnit.VisualStudio.TestAdapter.TestingPlatformAdapter.NUnitBridgedTestFramework.SynchronizedRunTestsAsync(VSTestRunTestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken) in C:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestingPlatformAdapter\NUnitBridgedTestFramework.cs:line 40
   at Microsoft.Testing.Extensions.VSTestBridge.SynchronizedSingleSessionVSTestBridgedTestFramework.<>c__DisplayClass22_0.<<ExecuteRequestAsync>b__0>d.MoveNext() in /_/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/SynchronizedSingleSessionVSTestAndTestAnywhereAdapter.cs:line 124
--- End of stack trace from previous location ---
   at Microsoft.Testing.Extensions.VSTestBridge.SynchronizedSingleSessionVSTestBridgedTestFramework.ExecuteRequestWithRequestCountGuardAsync(Func`1 asyncFunc) in /_/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/SynchronizedSingleSessionVSTestAndTestAnywhereAdapter.cs:line 145
   at Microsoft.Testing.Extensions.VSTestBridge.VSTestBridgedTestFrameworkBase.ExecuteRequestAsync(ExecuteRequestContext context) in /_/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/VSTestBridgedTestFrameworkBase.cs:line 77
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteRequestAsync(ITestFramework testFramework, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 75
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteAsync(ITestFramework testFramework, ClientInfo client, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 64
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.ExecuteRequestAsync(ProxyOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 136
   at Microsoft.Testing.Platform.Hosts.ServerTestHost.ExecuteRequestAsync(RequestArgsBase args, String method, ServiceProvider perRequestServiceProvider) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs:line 507
   at Microsoft.Testing.Platform.Hosts.ServerTestHost.ExecuteRequestAsync(RequestArgsBase args, String method, ServiceProvider perRequestServiceProvider) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs:line 539
   at Microsoft.Testing.Platform.Hosts.ServerTestHost.HandleRequestCoreAsync(RequestMessage message, RpcInvocationState rpcInvocationState) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs:line 433
   at Microsoft.Testing.Platform.Hosts.ServerTestHost.HandleRequestAsync(RequestMessage request, CancellationToken serverClosing) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs:line 339
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at Microsoft.VisualStudio.TestWindow.Internal.RemoteAgent.TestingPlatform.RpcClient.RunTestsWithFilterAsync(Guid runId, TestNode[] testNodes, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Threading.ThreadingTools.WithCancellationSlow[T](Task`1 task, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestWindow.Internal.RemoteAgent.TestingPlatform.Clients.TestingPlatformClient.ExecuteRpcCallAsync[T](Func`1 rpcFunction, CancellationToken cancellationToken)
RPC server exception:
: 


Steps To Reproduce

See attached file: repro.zip

Expected behavior

No error

Actual behavior

Above error

Reported by @aelij on microsoft/testfx#5047

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions