Remove `IDispatchImplAttribute` API (#76416)
authorAaron Robinson <arobins@microsoft.com>
Sat, 1 Oct 2022 00:04:49 +0000 (17:04 -0700)
committerGitHub <noreply@github.com>
Sat, 1 Oct 2022 00:04:49 +0000 (17:04 -0700)
* Remove IDispatchImplAttribute API

This type has never been supported on .NET Core.
Removing all supporting code paths.

12 files changed:
src/coreclr/vm/comcallablewrapper.cpp
src/coreclr/vm/comcallablewrapper.h
src/coreclr/vm/stdinterfaces.cpp
src/coreclr/vm/stdinterfaces_internal.h
src/coreclr/vm/wellknownattributes.h
src/libraries/System.Reflection.Metadata/tests/Resources/Interop/Interop.Mock01.cs
src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt
src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplAttribute.cs [deleted file]
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplType.cs [deleted file]
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/IDispatchImplAttributeTests.cs [deleted file]

index e0c5c06..0064fb3 100644 (file)
 #include "appdomain.inl"
 #include "typestring.h"
 
-// The enum that describes the value of the IDispatchImplAttribute custom attribute.
-enum IDispatchImplType
-{
-    SystemDefinedImpl   = 0,
-    InternalImpl        = 1,
-    CompatibleImpl      = 2
-};
-
 // The enum that describe the value of System.Runtime.InteropServices.CustomQueryInterfaceResult
 // It is the return value of the method System.Runtime.InteropServices.ICustomQueryInterface.GetInterface
 enum CustomQueryInterfaceResult
@@ -319,68 +311,6 @@ ComCallMethodDesc* ComMethodTable::ComCallMethodDescFromSlot(unsigned i)
 }
 
 //--------------------------------------------------------------------------
-// Determines if the Compatible IDispatch implementation is required for
-// the specified class.
-//--------------------------------------------------------------------------
-bool IsOleAutDispImplRequiredForClass(MethodTable *pClass)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_NOTRIGGER;
-        MODE_ANY;
-        PRECONDITION(CheckPointer(pClass));
-    }
-    CONTRACTL_END;
-
-    HRESULT             hr;
-    const BYTE *        pVal;
-    ULONG               cbVal;
-    Assembly *          pAssembly = pClass->GetAssembly();
-    IDispatchImplType   DispImplType = SystemDefinedImpl;
-
-    // First check for the IDispatchImplType custom attribute first.
-    hr = pClass->GetCustomAttribute(WellKnownAttribute::IDispatchImpl, (const void**)&pVal, &cbVal);
-    if (hr == S_OK)
-    {
-        CustomAttributeParser cap(pVal, cbVal);
-        IfFailThrow(cap.SkipProlog());
-        UINT8 u1;
-        IfFailThrow(cap.GetU1(&u1));
-
-        DispImplType = (IDispatchImplType)u1;
-        if ((DispImplType > 2) || (DispImplType < 0))
-            DispImplType = SystemDefinedImpl;
-    }
-
-    // If the custom attribute was set to something other than system defined then we will use that.
-    if (DispImplType != SystemDefinedImpl)
-        return (bool) (DispImplType == CompatibleImpl);
-
-    // Check to see if the assembly has the IDispatchImplType attribute set.
-    hr = pAssembly->GetCustomAttribute(pAssembly->GetManifestToken(), WellKnownAttribute::IDispatchImpl, (const void**)&pVal, &cbVal);
-    if (hr == S_OK)
-    {
-        CustomAttributeParser cap(pVal, cbVal);
-        IfFailThrow(cap.SkipProlog());
-        UINT8 u1;
-        IfFailThrow(cap.GetU1(&u1));
-
-        DispImplType = (IDispatchImplType)u1;
-        if ((DispImplType > 2) || (DispImplType < 0))
-            DispImplType = SystemDefinedImpl;
-    }
-
-    // If the custom attribute was set to something other than system defined then we will use that.
-    if (DispImplType != SystemDefinedImpl)
-        return (bool) (DispImplType == CompatibleImpl);
-
-    // Removed registry key check per reg cleanup bug 45978
-    // Effect: Will return false so code cleanup
-    return false;
-}
-
-//--------------------------------------------------------------------------
 // This routine is called anytime a com method is invoked for the first time.
 // It is responsible for generating the real stub.
 //
@@ -4733,12 +4663,6 @@ ComCallWrapperTemplate* ComCallWrapperTemplate::CreateTemplate(TypeHandle thClas
             pTemplate->m_flags |= enum_SupportsIClassX;
         }
 
-        if (IsOleAutDispImplRequiredForClass(pMT))
-        {
-            // Determine what IDispatch implementation this class should use
-            pTemplate->m_flags |= enum_UseOleAutDispatchImpl;
-        }
-
         // Eagerly create the interface CMTs.
         // when iterate the interfaces implemented by the methodtable, we can check whether
         // the interface supports ICustomQueryInterface.
index d4b0ebf..71b79ca 100644 (file)
@@ -255,12 +255,6 @@ public:
         return (m_flags & enum_RepresentsVariantInterface);
     }
 
-    BOOL IsUseOleAutDispatchImpl()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return (m_flags & enum_UseOleAutDispatchImpl);
-    }
-
     BOOL ImplementsIMarshal()
     {
         LIMITED_METHOD_CONTRACT;
@@ -327,7 +321,7 @@ private:
 
         enum_RepresentsVariantInterface       = 0x400, // this is a template for an interface with variance
 
-        enum_UseOleAutDispatchImpl            = 0x800, // the class is decorated with IDispatchImplAttribute(CompatibleImpl)
+        // enum_Unused                        = 0x800,
 
         enum_ImplementsIMarshal               = 0x1000, // the class implements a managed interface with Guid == IID_IMarshal
 
index 44022ca..cffce98 100644 (file)
@@ -1172,12 +1172,6 @@ Dispatch_GetIDsOfNames(IDispatch* pDisp, REFIID riid, _In_reads_(cNames) OLECHAR
         if (pCMT->HasInvisibleParent())
             return E_NOTIMPL;
 
-    ComCallWrapperTemplate *pTemplate = MapIUnknownToWrapper(pDisp)->GetComCallWrapperTemplate();
-    if (pTemplate->IsUseOleAutDispatchImpl())
-    {
-        return OleAutDispatchImpl_GetIDsOfNames(pDisp, riid, rgszNames, cNames, lcid, rgdispid);
-    }
-
     return InternalDispatchImpl_GetIDsOfNames(pDisp, riid, rgszNames, cNames, lcid, rgdispid);
 }
 
@@ -1212,124 +1206,9 @@ Dispatch_Invoke
         if (pCMT->HasInvisibleParent())
             return E_NOTIMPL;
 
-    ComCallWrapperTemplate *pTemplate = MapIUnknownToWrapper(pDisp)->GetComCallWrapperTemplate();
-    if (pTemplate->IsUseOleAutDispatchImpl())
-    {
-        return OleAutDispatchImpl_Invoke(pDisp, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
-    }
-
     return InternalDispatchImpl_Invoke(pDisp, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
 }
 
-
-//------------------------------------------------------------------------------------------
-//  IDispatch methods for COM+ objects implemented internally using reflection.
-
-
-HRESULT __stdcall
-OleAutDispatchImpl_GetIDsOfNames
-(
-    IDispatch* pDisp,
-    REFIID riid,
-    _In_reads_(cNames) OLECHAR **rgszNames,
-    unsigned int cNames,
-    LCID lcid,
-    DISPID *rgdispid
-)
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_TRIGGERS;
-        MODE_PREEMPTIVE;
-        INJECT_FAULT(return E_OUTOFMEMORY);
-        PRECONDITION(CheckPointer(pDisp));
-        PRECONDITION(IsInProcCCWTearOff(pDisp));
-        PRECONDITION(CheckPointer(rgszNames));
-    }
-    CONTRACTL_END;
-
-    // Make sure that riid is IID_NULL.
-    if (riid != IID_NULL)
-        return DISP_E_UNKNOWNINTERFACE;
-
-    // Retrieve the COM method table from the IP.
-    ComMethodTable *pCMT = ComMethodTable::ComMethodTableFromIP(pDisp);
-    if (pCMT->IsIClassXOrBasicItf() && pCMT->GetClassInterfaceType() != clsIfNone)
-        if (pCMT->HasInvisibleParent())
-            return E_NOTIMPL;
-
-    ITypeInfo *pTI;
-    HRESULT hr = GetITypeInfoForMT(pCMT, &pTI);
-    if (FAILED(hr))
-        return (hr);
-
-    hr = pTI->GetIDsOfNames(rgszNames, cNames, rgdispid);
-    return hr;
-}
-
-HRESULT __stdcall
-OleAutDispatchImpl_Invoke
-    (
-    IDispatch* pDisp,
-    DISPID dispidMember,
-    REFIID riid,
-    LCID lcid,
-    unsigned short wFlags,
-    DISPPARAMS *pdispparams,
-    VARIANT *pvarResult,
-    EXCEPINFO *pexcepinfo,
-    unsigned int *puArgErr
-    )
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_TRIGGERS;
-        MODE_PREEMPTIVE;
-        PRECONDITION(CheckPointer(pDisp));
-        PRECONDITION(IsInProcCCWTearOff(pDisp));
-    }
-    CONTRACTL_END;
-
-    HRESULT hr = S_OK;
-
-    // Make sure that riid is IID_NULL.
-    if (riid != IID_NULL)
-        return DISP_E_UNKNOWNINTERFACE;
-
-    // Retrieve the COM method table from the IP.
-    ComMethodTable *pCMT = ComMethodTable::ComMethodTableFromIP(pDisp);
-    if (pCMT->IsIClassXOrBasicItf() && pCMT->GetClassInterfaceType() != clsIfNone)
-        if (pCMT->HasInvisibleParent())
-            return E_NOTIMPL;
-
-    ITypeInfo *pTI;
-    hr = GetITypeInfoForMT(pCMT, &pTI);
-    if (FAILED(hr))
-        return hr;
-
-    EX_TRY
-    {
-        // If we have a basic or IClassX interface then we're going to invoke through
-        //  the class interface.
-        if (pCMT->IsIClassXOrBasicItf())
-        {
-            CCWHolder pCCW = ComCallWrapper::GetWrapperFromIP(pDisp);
-            pDisp = (IDispatch*)pCCW->GetIClassXIP();
-        }
-
-        hr = pTI->Invoke(pDisp, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
-    }
-    EX_CATCH
-    {
-        hr = GET_EXCEPTION()->GetHR();
-    }
-    EX_END_CATCH(SwallowAllExceptions);
-
-    return hr;
-}
-
 HRESULT __stdcall
 InternalDispatchImpl_GetIDsOfNames (
     IDispatch* pDisp,
index bd1b7b3..a268f56 100644 (file)
@@ -93,34 +93,6 @@ HRESULT __stdcall   Dispatch_Invoke (
                                     EXCEPINFO *pexcepinfo,
                                     unsigned int *puArgErr);
 
-
-//------------------------------------------------------------------------------------------
-//      IDispatch methods for COM+ objects that use our OleAut's implementation.
-
-
-// IDispatch::GetIDsofNames
-HRESULT __stdcall   OleAutDispatchImpl_GetIDsOfNames (
-                                    IDispatch* pDisp,
-                                    REFIID riid,
-                                    _In_reads_(cNames) OLECHAR **rgszNames,
-                                    unsigned int cNames,
-                                    LCID lcid,
-                                    DISPID *rgdispid);
-
-// IDispatch::Invoke
-HRESULT __stdcall   OleAutDispatchImpl_Invoke (
-                                    IDispatch* pDisp,
-                                    DISPID dispidMember,
-                                    REFIID riid,
-                                    LCID lcid,
-                                    unsigned short wFlags,
-                                    DISPPARAMS *pdispparams,
-                                    VARIANT *pvarResult,
-                                    EXCEPINFO *pexcepinfo,
-                                    unsigned int *puArgErr);
-
-
-
 //------------------------------------------------------------------------------------------
 //      IDispatch methods for COM+ objects that use our internal implementation.
 
index b247d62..f1ac8a6 100644 (file)
@@ -22,7 +22,6 @@ enum class WellKnownAttribute : DWORD
     DefaultDllImportSearchPaths,
     Guid,
     LCIDConversion,
-    IDispatchImpl,
     ImportedFromTypeLib,
     Intrinsic,
     IsByRefLike,
@@ -77,8 +76,6 @@ inline const char *GetWellKnownAttributeName(WellKnownAttribute attribute)
             return "System.Runtime.InteropServices.GuidAttribute";
         case WellKnownAttribute::LCIDConversion:
             return "System.Runtime.InteropServices.LCIDConversionAttribute";
-        case WellKnownAttribute::IDispatchImpl:
-            return "System.Runtime.InteropServices.IDispatchImplAttribute";
         case WellKnownAttribute::ImportedFromTypeLib:
             return "System.Runtime.InteropServices.ImportedFromTypeLibAttribute";
         case WellKnownAttribute::Intrinsic:
index 0ad8ac9..ef6ab5b 100644 (file)
@@ -17,7 +17,6 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(true)] // not embed
 [assembly: TypeLibVersion(1, 0)] // not embed
 // [assembly: SetWin32ContextInIDispatch()]
-// [assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)] // not embed
 
 namespace MockInterop01
 {
index dd2e06b..adf9d5b 100644 (file)
@@ -2,8 +2,6 @@ Compat issues with assembly System.Runtime.InteropServices:
 TypesMustExist : Type 'System.Runtime.InteropServices.AssemblyRegistrationFlags' does not exist in the reference but it does exist in the implementation.
 CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Runtime.InteropServices.ComWrappers' changed from '[UnsupportedOSPlatformAttribute("android")]' in the implementation to '[UnsupportedOSPlatformAttribute("android")]' in the reference.
 TypesMustExist : Type 'System.Runtime.InteropServices.ExporterEventKind' does not exist in the reference but it does exist in the implementation.
-TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplAttribute' does not exist in the reference but it does exist in the implementation.
-TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplType' does not exist in the reference but it does exist in the implementation.
 TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationClassContext' does not exist in the reference but it does exist in the implementation.
 TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationConnectionType' does not exist in the reference but it does exist in the implementation.
 TypesMustExist : Type 'System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute' does not exist in the reference but it does exist in the implementation.
index fc2048c..99e288f 100644 (file)
@@ -29,8 +29,6 @@
     <Compile Include="System\Runtime\InteropServices\ComUnregisterFunctionAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\ExporterEventKind.cs" />
     <Compile Include="System\Runtime\InteropServices\HandleCollector.cs" />
-    <Compile Include="System\Runtime\InteropServices\IDispatchImplAttribute.cs" />
-    <Compile Include="System\Runtime\InteropServices\IDispatchImplType.cs" />
     <Compile Include="System\Runtime\InteropServices\ImportedFromTypeLibAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\ManagedToNativeComInteropStubAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\PrimaryInteropAssemblyAttribute.cs" />
diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplAttribute.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplAttribute.cs
deleted file mode 100644 (file)
index dfe2ad0..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.InteropServices
-{
-    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, Inherited = false)]
-    [Obsolete("IDispatchImplAttribute has been deprecated and is not supported.")]
-    public sealed class IDispatchImplAttribute : Attribute
-    {
-        public IDispatchImplAttribute(short implType) : this((IDispatchImplType)implType)
-        {
-        }
-
-        public IDispatchImplAttribute(IDispatchImplType implType) => Value = implType;
-
-        public IDispatchImplType Value { get; }
-    }
-}
diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplType.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IDispatchImplType.cs
deleted file mode 100644 (file)
index fe674c3..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.InteropServices
-{
-    [Obsolete("IDispatchImplAttribute and IDispatchImplType have been deprecated and are not supported.")]
-    public enum IDispatchImplType
-    {
-        CompatibleImpl = 2,
-        InternalImpl = 1,
-        SystemDefinedImpl = 0,
-    }
-}
index 34964fb..867c373 100644 (file)
@@ -44,7 +44,6 @@
     <Compile Include="System\Runtime\InteropServices\GuidAttributeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\HandleCollectorTests.cs" />
     <Compile Include="System\Runtime\InteropServices\HandleRefTests.cs" />
-    <Compile Include="System\Runtime\InteropServices\IDispatchImplAttributeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\InterfaceTypeAttributeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\LCIDConversionAttributeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\LibraryImportAttributeTests.cs" />
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/IDispatchImplAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/IDispatchImplAttributeTests.cs
deleted file mode 100644 (file)
index ac19212..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Reflection;
-using Xunit;
-
-namespace System.Runtime.InteropServices.Tests
-{
-    public class IDispatchImplAttributeTests
-    {
-        [Theory]
-        [InlineData(-1)]
-        [InlineData(0)]
-        [InlineData(2)]
-        public void Ctor_ImplTypeShort(short implType)
-        {
-            Type type = Type.GetType("System.Runtime.InteropServices.IDispatchImplAttribute, System.Runtime.InteropServices");
-            PropertyInfo valueProperty = type.GetProperty("Value");
-            Assert.NotNull(type);
-            Assert.NotNull(valueProperty);
-
-            ConstructorInfo shortConstructor = type.GetConstructor(new Type[] { typeof(short) });
-            object attribute = shortConstructor.Invoke(new object[] { implType });
-            Assert.Equal(implType, (int)valueProperty.GetValue(attribute));
-        }
-    }
-}