Skip to content

Commit

Permalink
Avoid crash when method is not found using FQN (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Jul 11, 2023
1 parent 7ebed2a commit 1e9779f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 1e9779f

Please sign in to comment.