Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "Breaking change - Casting COM object that implements IDispatchEx to IReflect now fails"
description: "Learn about the breaking change in .NET 10 RC 1 where casting a COM object that implements IDispatchEx to IReflect now fails."
ms.date: 11/17/2025
ai-usage: ai-assisted
---

# Casting COM object that implements IDispatchEx to IReflect now fails

Since .NET 5, casting a COM object that implements `IDispatchEx` to `IReflect` has been possible. However, all members on that `IReflect` instance would throw <xref:System.TypeLoadException>. Starting in .NET 10 RC 1, this behavior changed so that the cast now fails.

## Version introduced

.NET 10 RC 1

## Previous behavior

Previously, casting a COM object that implements `IDispatchEx` to `IReflect` would succeed.

```csharp
using System.Reflection;
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
Console.WriteLine("IReflect is " + (file is IReflect ? "supported" : "NOT supported"));
// Prints "IReflect is supported"
```

## New behavior

Starting in .NET 10, casting a COM object that implements `IDispatchEx` to `IReflect` now fails.

```csharp
using System.Reflection;
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
Console.WriteLine("IReflect is " + (file is IReflect ? "supported" : "NOT supported"));
// Prints "IReflect is NOT supported"
```

## Type of breaking change

This change is a [behavioral change](../../categories.md#behavioral-change).

## Reason for change

This was removed because all members on the resulting `IReflect` instance would be unusable. The <xref:System.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:

```csharp
var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
Console.WriteLine("IDispatchEx is " + (file is IDispatchEx ? "supported" : "NOT supported"));

[ComImport]
[Guid("A6EF9860-C720-11D0-9337-00A0C90DCAA9")]
interface IDispatchEx { }
```

## Affected APIs

None.
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ items:
href: install-tool/3.0.0/vscode-dotnet-acquire-no-latest.md
- name: Interop
items:
- name: Casting COM object that implements IDispatchEx to IReflect now fails
href: interop/10.0/idispatchex-ireflect-cast.md
- name: Single-file apps no longer look for native libraries in executable directory
href: interop/10.0/native-library-search.md
- name: Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory
Expand Down
Loading