Skip to content

Add back Marshal.IsTypeVisibleFromCom #26497

Closed

Description

@ericstj

I've encountered this in a number of places in Desktop code and cannot come up with a reasonable workaround to port the behavior. Given we still support COM interop on Windows and are investing more in that space we should bring this back.

We still have the implementation in CoreCLR we just need to expose it:
https://github.com/dotnet/coreclr/blob/46ab1d132c9ad471d79afa20c188c2f9c85e5f20/src/vm/marshalnative.cpp#L1523

/cc @luqunl

Activity

  1. ericstj commented on Jun 14, 2018

    @ericstj
    MemberAuthor

    As a (hack) workaround I did the following, which calls IsTypeVisibleFromCom behind the scenes.

            public static bool IsTypeVisibleFromCom(Type type)
            {
                try
                {
                    int unused = Marshal.GetStartComSlot(type);
                }
                catch (ArgumentException)
                {
                    if (type == null)
                    {
                        throw;
                    }
                    return false;
                }
                return true;
            }
    
  2. danmoseley commented on Jul 4, 2018

    @danmoseley
    Contributor

    There's quite a bit of Marshal missing as seen in
    https://github.com/dotnet/corefx/blob/master/src/shims/ApiCompatBaseline.netcoreapp.netfx461.ignore.txt#L2595-L2619

    It's not necessarily with good reason eg we have Marshal.GetStartComSlot(Type t) but not Marshal.GetEndComSlot(Type t). In fact most of them look portable - if we still have the native implementation and want to.

  3. luqunl commented on Jul 4, 2018

    @luqunl
    Contributor

    Marshal.GetStartComSlot(Type t) but not Marshal.GetEndComSlot(Type t)

    Agree. We should either support both or not support both..

    IsTypeVisibleFromCom

    We should add support. the question is its behavior. in desktop, almost all managed object is Visiable to COM. I am not sure what's right behavior for .NetCore

    There's quite a bit of Marshal missing as seen in
    https://github.com/dotnet/corefx/blob/master/src/shims/ApiCompatBaseline.netcoreapp.netfx461.ignore.txt#L2595-L2619

    I don't want to add these TypeLib related APIs.

  4. jkotas commented on Jul 4, 2018

    @jkotas
    Member

    I am not sure what's right behavior for .NetCore

    IsTypeVisibleFromCom is used internally by the COM interop subsystem. This API is just exposing the value publicly.

    If we were to change the rules for how COM visibility is computed in .NET Core, it should be looked at as separate issue. (I do not think we have a good reason to change the rules.)

    I don't want to add these TypeLib related APIs.

    Agree. Let's add only what we know is a real problem or clear inconsistency: IsTypeVisibleFromCom and GetEndComSlot.

  5. danmoseley commented on Jul 12, 2018

    @danmoseley
    Contributor

    @luqunl there is no need to review the API if it was already exposed in .NET Framework. That tag is for proposed new API, to review their shape, value etc. Do you plan to take these or is it up for grabs?

  6. danmoseley commented on Aug 13, 2018

    @danmoseley
    Contributor

    @luqunl what is the status of this one, do you plan to do it?

  7. luqunl commented on Aug 15, 2018

    @luqunl
    Contributor

    @danmosemsft , working on it.

  8. transferred this issue fromdotnet/corefxon Jan 31, 2020
  9. added this to the 3.0 milestone on Jan 31, 2020
  10. ghost locked as resolved and limited conversation to collaborators on Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions