Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ece8b8d

Browse files
committed
Disable COM interop for WinRT types
1 parent 671368e commit ece8b8d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/System.Private.CoreLib/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,9 @@
28842884
<data name="NotSupported_CollectibleBoundNonCollectible" xml:space="preserve">
28852885
<value>A non-collectible assembly may not reference a collectible assembly.</value>
28862886
</data>
2887+
<data name="NotSupported_CollectibleWinRT" xml:space="preserve">
2888+
<value>WinRT Interop is not supported for collectible types.</value>
2889+
</data>
28872890
<data name="NotSupported_CreateInstanceWithTypeBuilder" xml:space="preserve">
28882891
<value>CreateInstance cannot be used with an object of type TypeBuilder.</value>
28892892
</data>

src/vm/ceeload.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,12 @@ BOOL Module::CanCacheWinRTTypeByGuid(MethodTable *pMT)
837837
}
838838
CONTRACTL_END;
839839

840+
// Don't cache WinRT types in collectible modules.
841+
if (IsCollectible())
842+
{
843+
return FALSE;
844+
}
845+
840846
// Don't cache mscorlib-internal declarations of WinRT types.
841847
if (IsSystem() && pMT->IsProjectedFromWinRT())
842848
return FALSE;

src/vm/interoputil.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5161,6 +5161,14 @@ ClassFactoryBase *GetComClassFactory(MethodTable* pClassMT)
51615161

51625162
if (pClsFac == NULL)
51635163
{
5164+
//
5165+
// Collectible types do not support WinRT interop
5166+
//
5167+
if (pClassMT->IsExportedToWinRT() || pClassMT->IsProjectedFromWinRT())
5168+
{
5169+
COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleWinRT"));
5170+
}
5171+
51645172
NewHolder<ClassFactoryBase> pNewFactory;
51655173

51665174
if (pClassMT->IsExportedToWinRT())

0 commit comments

Comments
 (0)