Skip to content

Commit 51aae93

Browse files
authored
Add breaking change documentation for IDispatchEx to IReflect cast failure in .NET 10 (#49934)
1 parent e4b40cc commit 51aae93

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
9999

100100
| Title | Type of change |
101101
|-------|-------------------|
102+
| [Casting IDispatchEx COM object to IReflect fails](interop/10.0/idispatchex-ireflect-cast.md) | Behavioral change |
102103
| [Single-file apps no longer look for native libraries in executable directory](interop/10.0/native-library-search.md) | Behavioral change |
103104
| [Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory](interop/10.0/search-assembly-directory.md) | Behavioral change |
104105

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "Breaking change - Casting IDispatchEx COM object to IReflect fails"
3+
description: "Learn about the breaking change in .NET 10 where casting a COM object that implements IDispatchEx to IReflect now fails."
4+
ms.date: 11/17/2025
5+
ai-usage: ai-assisted
6+
---
7+
8+
# Casting COM object that implements IDispatchEx to IReflect fails
9+
10+
Since .NET 5, it was possible to cast a COM object that implements [IDispatchEx](/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/reference/idispatchex-interface) to <xref:System.Reflection.IReflect>. However, all members on that `IReflect` instance threw <xref:System.TypeLoadException>. Starting in .NET 10, this behavior changed and the cast now fails.
11+
12+
## Version introduced
13+
14+
.NET 10
15+
16+
## Previous behavior
17+
18+
Previously, casting a COM object that implements `IDispatchEx` to `IReflect` succeeded.
19+
20+
```csharp
21+
using System.Reflection;
22+
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
23+
Console.WriteLine("IReflect is " + (file is IReflect ? "supported" : "NOT supported"));
24+
// Printed "IReflect is supported".
25+
```
26+
27+
## New behavior
28+
29+
Starting in .NET 10, casting a COM object that implements `IDispatchEx` to `IReflect` fails.
30+
31+
```csharp
32+
using System.Reflection;
33+
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
34+
Console.WriteLine("IReflect is " + (file is IReflect ? "supported" : "NOT supported"));
35+
// Prints "IReflect is NOT supported".
36+
```
37+
38+
## Type of breaking change
39+
40+
This change is a [behavioral change](../../categories.md#behavioral-change).
41+
42+
## Reason for change
43+
44+
This capability was removed because all members on the resulting `IReflect` instance were unusable. Also, the <xref:System.TypeLoadException> exception that resulted from accessing any of the members mentioned a type that was never included in .NET and was therefore confusing and unhelpful as to the underlying issue.
45+
46+
## Recommended action
47+
48+
The only viable question that could be asked in .NET 5+ with this cast was, "Does the type implement IDispatchEx?" In this case, a better way to ask that question is:
49+
50+
```csharp
51+
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
52+
Console.WriteLine("IDispatchEx is " + (file is IDispatchEx ? "supported" : "NOT supported"));
53+
54+
[ComImport]
55+
[Guid("A6EF9860-C720-11D0-9337-00A0C90DCAA9")]
56+
interface IDispatchEx { }
57+
```
58+
59+
## Affected APIs
60+
61+
None.

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ items:
108108
href: install-tool/3.0.0/vscode-dotnet-acquire-no-latest.md
109109
- name: Interop
110110
items:
111+
- name: Casting IDispatchEx COM object to IReflect fails
112+
href: interop/10.0/idispatchex-ireflect-cast.md
111113
- name: Single-file apps no longer look for native libraries in executable directory
112114
href: interop/10.0/native-library-search.md
113115
- name: Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory

0 commit comments

Comments
 (0)