Skip to content

Implement Marshal.GetComObjectData and Marshal.SetComObjectData in .NET Core #26788

@hughbe

Description

@hughbe

These methods are stubbed out and throw PNSE in .NET Core. Looking at reference source it should be easy to implement (https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/src/System/__ComObject.cs#L66-L108)

public static Object GetComObjectData(Object obj, Object key)
{
    if (obj == null)
    {
        throw new ArgumentNullException(nameof(obj));
    }
    if (key == null)
    {
        throw new ArgumentNullException(nameof(key));
    }

    __ComObject comObj = null;

    // Make sure the obj is an __ComObject.
    try
    {
        comObj = (__ComObject)obj;
    }
    catch (InvalidCastException)
    {
        throw new ArgumentException(SR.Argument_ObjNotComObject, nameof(obj))
    }

    if (obj.GetType().IsWindowsRuntimeObject)
    {
        throw new ArgumentException(SR.Argument_ObjIsWinRTObject, nameof(obj));
    }

    // Retrieve the data from the __ComObject.
    return comObj.GetData(key);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions