This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Disable marshalling delegates as _Delegate and enable marshalling delegates as IDispatch.#23738
Merged
jkoritzinsky merged 3 commits intodotnet:masterfrom Apr 5, 2019
Conversation
…egates as IDispatch.
394e51a to
8c7a3f3
Compare
AaronRobinsonMSFT
approved these changes
Apr 4, 2019
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
…egates as IDispatch. (dotnet/coreclr#23738) * Disable marshalling delegates as _Delegate and enable marshalling delegates as IDispatch. * ifdef out the new IDispatch marshalling on non-COM-supporting platforms. * PR feedback. Commit migrated from dotnet/coreclr@8241971
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
As part of the transition to .NET Core, we dropped the concept of the mscorlib tlb interfaces. However, in the marshalling space we continued to imply that their usage was safe, particularly with delegates. In .NET Framework, it is possible to marshal a delegate as a COM object implementing the
_Delegateinterface provided by themscorlib.tlbtype library. Since we did not make many significant changes to theSystem.Delegatetype in .NET Core, this behavior continued to work in .NET Core. However, when theSystem.Delegatetype was moved to the shared partition in #23552, the change to the compiled type's surface was large enough to change how the dispid's were assigned, breaking the marshalling to the Framework_Delegateinterface and resulting in bad runtime errors (crashes, incorrect return values depending on exactly how the interface pointer is generated).We've decided that since the
_DelegateCOM interface is a .NET Framework type, that we are not going to try to add back support to marshalling to it. Instead, we are changing behavior as follows:[MarshalAs(UnmanagedType.Interface)]on a delegate-typed field, parameter, or return value is illegal.[MarshalAs(UnmanagedType.Interface)].[MarshalAs(UnmanagedType.IDispatch)]on a delegate-typed field, parameter or return value is now legal and is the suggested change for consumers. Additionally, these consumers will have to change their native code to take anIDispatchpointer and operate on the delegate's COM wrapper via theIDispatchinterface instead of the_Delegateinterface.Fixes #23730.