diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs b/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs index 5237216819..383145c49d 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs @@ -656,9 +656,16 @@ private MethodInfo GetMethodInfoForTestMethod(TestMethod testMethod, TestClassIn private static MethodInfo? GetMethodInfoUsingManagedNameHelper(TestMethod testMethod, TestClassInfo testClassInfo, bool discoverInternals) { - MethodInfo? testMethodInfo = null; - var methodBase = ManagedNameHelper.GetMethod(testClassInfo.Parent.Assembly, testMethod.ManagedTypeName!, testMethod.ManagedMethodName!); + MethodBase? methodBase = null; + try + { + methodBase = ManagedNameHelper.GetMethod(testClassInfo.Parent.Assembly, testMethod.ManagedTypeName!, testMethod.ManagedMethodName!); + } + catch (InvalidManagedNameException) + { + } + MethodInfo? testMethodInfo = null; if (methodBase is MethodInfo mi) { testMethodInfo = mi; @@ -669,9 +676,11 @@ private MethodInfo GetMethodInfoForTestMethod(TestMethod testMethod, TestClassIn testMethodInfo = methodBase.DeclaringType!.GetRuntimeMethod(methodBase.Name, parameters); } - testMethodInfo = testMethodInfo?.HasCorrectTestMethodSignature(true, discoverInternals) ?? false - ? testMethodInfo - : null; + if (testMethodInfo is null + || !testMethodInfo.HasCorrectTestMethodSignature(true, discoverInternals)) + { + return null; + } return testMethodInfo; }