Skip to content

Commit a9195ee

Browse files
committed
NotSupportedException on marshalling class to variant without type lib
1 parent 059fad6 commit a9195ee

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/coreclr/dlls/mscorrc/mscorrc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ BEGIN
524524
IDS_EE_INVALIDCOMDEFITF "Type '%1' has an invalid default COM interface: '%2'."
525525
IDS_EE_COMDEFITFNOTSUPPORTED "Type '%1' does not support the specified default COM interface: '%2'"
526526

527+
IDS_EE_CLASS_TO_VARIANT_TLB_NOT_REG "Type '%1' cannot be marshalled to a Variant. Type library is not registered."
527528
IDS_EE_CANNOT_MAP_TO_MANAGED_VC "The specified record cannot be mapped to a managed value class."
528529

529530
IDS_EE_SAFEHANDLECLOSED "Safe handle has been closed"

src/coreclr/dlls/mscorrc/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
#define IDS_EE_INVALIDCOMDEFITF 0x1a32
271271
#define IDS_EE_COMDEFITFNOTSUPPORTED 0x1a33
272272

273+
#define IDS_EE_CLASS_TO_VARIANT_TLB_NOT_REG 0x1a35
273274
#define IDS_EE_CANNOT_MAP_TO_MANAGED_VC 0x1a36
274275

275276
#define IDS_EE_MARSHAL_UNMAPPABLE_CHAR 0x1a37

src/coreclr/vm/olevariant.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4710,7 +4710,21 @@ void OleVariant::ConvertValueClassToVariant(OBJECTREF *pBoxedValueClass, VARIANT
47104710

47114711
// Retrieve the ITypeInfo for the value class.
47124712
MethodTable *pValueClassMT = (*pBoxedValueClass)->GetMethodTable();
4713-
IfFailThrow(GetITypeInfoForEEClass(pValueClassMT, &pTypeInfo, true /* bClassInfo */));
4713+
hr = GetITypeInfoForEEClass(pValueClassMT, &pTypeInfo, true /* bClassInfo */);
4714+
if (FAILED(hr))
4715+
{
4716+
if (hr == TLBX_E_LIBNOTREGISTERED)
4717+
{
4718+
// Indicate that conversion of the class to variant without a registered type lib is not supported
4719+
StackSString className;
4720+
pValueClassMT->_GetFullyQualifiedNameForClass(className);
4721+
COMPlusThrow(kNotSupportedException, IDS_EE_CLASS_TO_VARIANT_TLB_NOT_REG, className.GetUnicode());
4722+
}
4723+
else
4724+
{
4725+
COMPlusThrowHR(hr);
4726+
}
4727+
}
47144728

47154729
// Convert the ITypeInfo to an IRecordInfo.
47164730
hr = GetRecordInfoFromTypeInfo(pTypeInfo, &V_RECORDINFO(pRecHolder));

0 commit comments

Comments
 (0)