Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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"
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type names like IDispatchEx and IReflect should be wrapped in backticks for code formatting according to .NET documentation guidelines. Change the title to: "Breaking change: Casting COM object that implements IDispatchEx to IReflect now fails".

Copilot generated this review using guidance from repository custom instructions.
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to markdown writing guidelines, use a colon instead of a hyphen in the title. Change "Breaking change -" to "Breaking change:".

Copilot generated this review using guidance from repository custom instructions.
description: "Learn about the breaking change in .NET 10 RC 1 where casting a COM object that implements IDispatchEx to IReflect now fails."
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type names like IDispatchEx and IReflect should be wrapped in backticks for code formatting according to .NET documentation guidelines. Update the description to include backticks around these type names.

Copilot generated this review using guidance from repository custom instructions.
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:
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use second person ("you") instead of passive voice. Change "In this case, the better way to ask that question is as follows:" to "In this case, ask that question as follows:" to follow the active voice with second person requirements.

Copilot generated this review using guidance from repository custom instructions.

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

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace at the end of the line.

Suggested change
Console.WriteLine("IDispatchEx is " + (file is IDispatchEx ? "supported" : "NOT supported"));
Console.WriteLine("IDispatchEx is " + (file is IDispatchEx ? "supported" : "NOT supported"));

Copilot uses AI. Check for mistakes.

[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