The joy (or rather not so joyful) of COM interop

It turns out that the ISimpleList and IDictionary objects will not always return to you a value which is typed with the .NET equivalent types.  It makes for a bit of a sticky situation when you are trying to determine if the type is compatible in the world of generic collections.  I had to make a key change to my wrapper to address this issue when checking type compatibility by using the Type.IsInstanceOfType method (a substitute for the as operator noted in the KB350523):

// If the type is a value type then rule it out right away if it is
// a null value.  Otherwise check to see if it is an instance of
// or assignable to the target type.
if ((!type.IsValueType && ((variable == null) || Convert.IsDBNull(variable))) ||
    (variable != null && (type.IsInstanceOfType(variable) || type.IsAssignableFrom(variable.GetType()))))
{
    isTypeCompatible = true;
}

Comments Subscribe to Post Comments Feed

Be the first to share your opinion!

Have Your Say