-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add breaking change documentation for IDispatchEx to IReflect cast failure in .NET 10 #49934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+64
−0
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/core/compatibility/interop/10.0/idispatchex-ireflect-cast.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: "Learn about the breaking change in .NET 10 RC 1 where casting a COM object that implements IDispatchEx to IReflect now fails." | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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: | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| var file = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile")); | ||
| Console.WriteLine("IDispatchEx is " + (file is IDispatchEx ? "supported" : "NOT supported")); | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [ComImport] | ||
| [Guid("A6EF9860-C720-11D0-9337-00A0C90DCAA9")] | ||
| interface IDispatchEx { } | ||
| ``` | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| None. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.