public IntPtr InstantiateType(IntPtr type) { try { var typeName = Utilities.ContainerToString(Interop.NetTypeInfo.GetFullTypeName(type)); var typeInfo = Type.GetType(typeName); if (typeInfo == null) { throw new InvalidOperationException($"Invalid type {typeName}"); } var netReference = NetReference.CreateForObject(TypeCreator.Create(typeInfo)); // When .NET collects this NetReference, we don't want it to delete this // handle. Ownership has been passed to the caller. return(Interop.NetReference.Clone(netReference.Handle)); } finally { Interop.NetTypeInfo.Destroy(type); } }