internal static ComInteropProxy CreateProxy (Type t)
{
ComInteropProxy proxy = new ComInteropProxy (t);
proxy.com_object.Initialize (t);
ComInteropProxy cachedProxy = FindProxy (proxy.com_object.IUnknown);
if (cachedProxy != null) {
// check that the COM type of the cached proxy matches
// the requested type. See 2nd part of bug #520437.
Type cachedType = cachedProxy.com_object.GetType ();
if (cachedType != t)
throw new InvalidCastException (String.Format ("Unable to cast object of type '{0}' to type '{1}'.", cachedType, t));
return cachedProxy;
}
return proxy;
}