Bug Fix: Type compatibility check failed for object target type
What was broken
TypeExtensions.IsImplicitCastableTo() did not handle the fundamental .NET rule that every type is implicitly assignable to System.Object. This caused
InvokeHelper.InvokeMethodAsync<object>() to throw:
Method returns a Type of 'IAsyncEnumerable`1[System.Object]' which is not implicitly castable to System.Object
The bug affected any method returning an interface type (e.g. IAsyncEnumerable<T>, IEnumerable<T>, IDisposable), because interfaces have no BaseType in .NET
reflection metadata — so InheritFromClass<object>() returned false, and none of the other checks (ImplementsInterface, IsImplicitCastableTo, implicit operators)
cover the object case either.
Root cause
This is a follow-up to the v1.0.1 fix for NotEquals<T>(). In v1.0.0, NotEquals<T>() always returned false, which inadvertently skipped the entire type compatibility
check. The v1.0.1 fix made the check work correctly — but exposed this gap.
Fix
Added an early return if (to == typeof(object)) return true in IsImplicitCastableTo().