@@ -103,25 +103,29 @@ internal static string GetNameOfType(ComTypes.ITypeInfo typeInfo)
103
103
}
104
104
105
105
/// <summary>
106
- /// Look for typeinfo using IDispatch.GetTypeInfo
106
+ /// Look for type info using IDispatch.GetTypeInfo
107
107
/// </summary>
108
108
/// <param name="dispatch">IDispatch object</param>
109
109
/// <remarks>
110
- /// Some COM objects just dont expose typeinfo . In these cases, this method will return null.
111
- /// Some COM objects do intend to expose typeinfo , but may not be able to do so if the type-library is not properly
112
- /// registered. This will be considered as acceptable or as an error condition depending on throwIfMissingExpectedTypeInfo
110
+ /// Some COM objects just don't expose type info . In these cases, this method will return null.
111
+ /// Some COM objects do intend to expose type info , but may not be able to do so if the type library
112
+ /// is not properly registered. This will be considered an error.
113
113
/// </remarks>
114
114
/// <returns>Type info</returns>
115
115
internal static ComTypes . ITypeInfo GetITypeInfoFromIDispatch ( IDispatch dispatch )
116
116
{
117
117
int hresult = dispatch . TryGetTypeInfoCount ( out uint typeCount ) ;
118
- Marshal . ThrowExceptionForHR ( hresult ) ;
119
- Debug . Assert ( typeCount <= 1 ) ;
120
118
if ( typeCount == 0 )
121
119
{
120
+ // COM objects should return a type count of 0 to indicate that type info is not exposed.
121
+ // Some COM objects may return a non-success HRESULT when type info is not supported, so
122
+ // we only check the count and not the HRESULT in this case.
122
123
return null ;
123
124
}
124
125
126
+ Marshal . ThrowExceptionForHR ( hresult ) ;
127
+ Debug . Assert ( typeCount == 1 ) ;
128
+
125
129
IntPtr typeInfoPtr ;
126
130
hresult = dispatch . TryGetTypeInfo ( 0 , 0 , out typeInfoPtr ) ;
127
131
if ( ! ComHresults . IsSuccess ( hresult ) )
0 commit comments