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
[Breaking change]: Casting COM object that implements IDispatchEx to IReflect now fails #49921
Since .NET 5, the ability to cast a COM object that implements IDispatchEx to IReflect has been possible. However, all members on that IReflect instance would throw TypeLoadException. In .NET 10 this behavior changed so that the cast will fail.
Version
.NET 10 RC 1
Previous behavior
Casting a COM object that implements IDispatchEx to IReflect would succeed.
usingSystem.Reflection;varfile=Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));Console.WriteLine("IReflect is "+(fileisIReflect?"supported":"NOT supported"));// Prints "IReflect is supported"
New behavior
Casting a COM object that implements IDispatchEx to IReflect will now fail.
usingSystem.Reflection;varfile=Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));Console.WriteLine("IReflect is "+(fileisIReflect?"supported":"NOT supported"));// Prints "IReflect is NOT supported"
Type of breaking change
Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
Behavioral change: Existing binaries might behave differently at run time.
Reason for change
This was removed since all members on the resulting IReflect instance would be unusable. The TypeLoadException exception that would result from accessing any of the members mentioned a type that was never included in .NET Core and was therefore confusing and unhelpful as to the underlying issue. Removal of the cast behavior was therefore deemed appropriate.
Recommended action
The only viable question that could be asked in .NET 5+ with this cast was, "Does the type implement IDispatchEx?" In this case, the better way to ask that question is as follows:
varfile=Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));Console.WriteLine("IDispatchEx is "+(fileisIDispatchEx?"supported":"NOT supported"));[ComImport][Guid("A6EF9860-C720-11D0-9337-00A0C90DCAA9")]interfaceIDispatchEx{}
Activity
AaronRobinsonMSFT commentedon Nov 15, 2025
/cc @davidwrighton @jkotas @ClearScriptLib
AaronRobinsonMSFT commentedon Nov 15, 2025
/cc @dotnet/interop-contrib
teo-tsirpanis commentedon Nov 17, 2025
Why will
file is IReflectthrow; shouldn't it returnfalse?AaronRobinsonMSFT commentedon Nov 17, 2025
Updated.