Skip to content

Commit 5d0e0d0

Browse files
[Mvc] Avoid exception in route analyzer (#63033)
Resolves #59735.
1 parent 9cdd601 commit 5d0e0d0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Shared/Roslyn/MvcFacts.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public static bool IsControllerAction(IMethodSymbol method, INamedTypeSymbol non
7070
}
7171

7272
// Overridden methods from Object class, e.g. Equals(Object), GetHashCode(), etc., are not valid.
73-
if (GetDeclaringType(method).SpecialType == SpecialType.System_Object)
73+
var declaringType = GetDeclaringType(method);
74+
if (declaringType == null || declaringType.SpecialType == SpecialType.System_Object)
7475
{
7576
return false;
7677
}
@@ -98,13 +99,13 @@ public static bool IsControllerAction(IMethodSymbol method, INamedTypeSymbol non
9899
return method.DeclaredAccessibility == Accessibility.Public;
99100
}
100101

101-
private static INamedTypeSymbol GetDeclaringType(IMethodSymbol method)
102+
private static INamedTypeSymbol? GetDeclaringType(IMethodSymbol method)
102103
{
103104
while (method.IsOverride)
104105
{
105106
if (method.OverriddenMethod == null)
106107
{
107-
throw new InvalidOperationException($"{nameof(method.OverriddenMethod)} cannot be null.");
108+
return null;
108109
}
109110

110111
method = method.OverriddenMethod;

0 commit comments

Comments
 (0)