Skip to content
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

Add marshallers for GeneratedComInterface-based types #86177

Merged
merged 16 commits into from
May 20, 2023

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented May 12, 2023

  • Add the marshallers defined in [API Proposal]: Define parameter marshalling of interfaces #85797 (fixes [API Proposal]: Define parameter marshalling of interfaces #85797)
  • Add default marshalling rules for GeneratedComInterface-attributed types.
  • Allow [MarshalAs(UnmanagedType.Interface)] on all types. If the type has the GeneratedComInterface attribute, then the object will be marshalled as that COM interface. Otherwise it will be marshalled as IUnknown* for whatever managed object wrapper is returned from a default-constructed StrategyBasedComWrappers instance.
    • If we want, we can limit this to types with [GeneratedComInterface] or [GeneratedComClass] or the object type. This may be more restrictive than required (an abstract base type of a [GeneratedComClass] type would be reasonable to have in a parameter list and would be expensive to reliably detect), but we could design some simple rules to limit invalid usage.

Some of the integration tests are disabled due to the following issue:

Since CreateObjectFlags.Unwrap will unwrap any Managed Object Wrapper from any ComWrappers instance, we can easily get into a bad state if a COM object is implemented by ComWrappers under the hood. Our tests capture this pretty well as the "native" side is loaded into a separate ALC, so the tests fail as the underlying managed object cannot be cast to the interface on the "managed" side of the test. We need to determine a solution for this problem and enable those tests before we merge in this work. We will resolve this problem by changing the behavior of CreateObjectFlags.Unwrap to be ComWrappers-specific. This change is specified in #86189

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented May 12, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Add the marshallers defined in [API Proposal]: Define parameter marshalling of interfaces #85797 (fixes [API Proposal]: Define parameter marshalling of interfaces #85797)
  • Add default marshalling rules for GeneratedComInterface-attributed types.
  • Allow [MarshalAs(UnmanagedType.Interface)] on all types. If the type has the GeneratedComInterface attribute, then the object will be marshalled as that COM interface. Otherwise it will be marshalled as IUnknown* for whatever managed object wrapper is returned from a default-constructed StrategyBasedComWrappers instance.
    • If we want, we can limit this to types with [GeneratedComInterface] or [GeneratedComClass] or the object type. This may be more restrictive than required (an abstract base type of a [GeneratedComClass] type would be reasonable to have in a parameter list and would be expensive to reliably detect), but we could design some simple rules to limit invalid usage.

Some of the integration tests are disabled due to the following issue:

Since CreateObjectFlags.Unwrap will unwrap any Managed Object Wrapper from any ComWrappers instance, we can easily get into a bad state if a COM object is implemented by ComWrappers under the hood. Our tests capture this pretty well as the "native" side is loaded into a separate ALC, so the tests fail as the underlying managed object cannot be cast to the interface on the "managed" side of the test. We need to determine a solution for this problem and enable those tests before we merge in this work.

Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

@jkoritzinsky jkoritzinsky removed the blocked Issue/PR is blocked on something - see comments label May 15, 2023
@jkoritzinsky jkoritzinsky merged commit fdb5ac7 into dotnet:main May 20, 2023
@jkoritzinsky jkoritzinsky deleted the interface-marshallers branch May 20, 2023 01:59
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Define parameter marshalling of interfaces
3 participants