You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TryFindMethod returns false for methods an interface inherits from its base interfaces: typeof(IList<int>).TryFindMethod("Add", …) finds nothing #158
ReflectionExtensions.TryFindMethod (Extensions/ReflectionExtensions.cs:30-38) climbs the type hierarchy through Type.BaseType. An interface type's BaseType is always null, and Type.GetMethod on an interface does not search the interfaces it extends. So when type is an interface, the search covers only the interface's own declared members. Every method inherited from a base interface is reported as missing, even though the doc comment says the method "walks up the inheritance tree".
Reproduction (run against a local build, net10.0)
usingSystem.Reflection;usingktsu.Extensions;publicinterfaceIBase{voidBaseOp();}publicinterfaceIDerived:IBase{}varflags=BindingFlags.Public|BindingFlags.Instance;typeof(IDerived).TryFindMethod("BaseOp",flags,outvarm1);// false, m1 == nulltypeof(IList<int>).TryFindMethod("Add",flags,outvarm2);// false (Add is declared on ICollection<T>)typeof(IList<int>).TryFindMethod("GetEnumerator",flags,outvarm3);// false (declared on IEnumerable<T>)typeof(ICollection<int>).TryFindMethod("Add",flags,outvarm4);// true
Expected: true in all four cases, with methodInfo pointing at the method on the interface that declares it.
Why it matters
Code that discovers members by convention is often handed an interface type, such as a service contract or typeof(IList<T>). For those types the method returns false for members that do exist. Because this is a Try method, the caller reads false as "not present" and silently skips the member or takes a fallback path, with no error to point at the cause. The existing tests in ReflectionExtensionsTests.cs cover class inheritance only.
Suggested fix / acceptance criteria
When type.IsInterface and no match is found on type itself, also search type.GetInterfaces(), which returns every inherited interface.
All four repro lines above return true, and methodInfo.DeclaringType is the interface that declares the method.
Priority: Medium. A Try* method silently returns false for members that exist on interface types such as IList<T>.Add. Callers read that as "not present" and take fallback paths with no error, which contradicts the doc comment's "walks up the inheritance tree".
Area / suggested assignment:Extensions/ReflectionExtensions.cs (TryFindMethod) and ReflectionExtensionsTests.cs.
Suggested next step: When type.IsInterface, fall back to searching type.GetInterfaces(). Add a two-level interface hierarchy test plus the IList<int> cases from the issue.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
Try*method silently returnsfalsefor members that exist on interface types such asIList<T>.Add. Callers read that as "not present" and take fallback paths with no error, which contradicts the doc comment's "walks up the inheritance tree".Extensions/ReflectionExtensions.cs(TryFindMethod) andReflectionExtensionsTests.cs.Suggested next step: When
type.IsInterface, fall back to searchingtype.GetInterfaces(). Add a two-level interface hierarchy test plus theIList<int>cases from the issue.Generated by Claude Code
[patch] Resolve overloads in TryFindMethod and search inherited inter…