//[LoaderOptimization(LoaderOptimization.MultiDomain)]
        public static IntPtr DllGetClassObject(IntPtr prclsid, IntPtr priid, out IntPtr ppv)
        {
            Guid rclsid = (Guid)Marshal.PtrToStructure(prclsid, typeof(Guid));
            Guid riid   = (Guid)Marshal.PtrToStructure(priid, typeof(Guid));

            ppv = IntPtr.Zero;

            try
            {
                ComInfo comInfo = ComInfo.GetComInfoFromClsid(rclsid);

                if (ComHelper.GuidIsIn(riid,
                                       comInfo.ClsId,
                                       ComHelper.IID_IClassFactory,
                                       ComHelper.IID_IUnknown,
                                       ComHelper.IID_IDispatch,
                                       ComHelper.IID_IOleObject))
                {
                    Type type = typeof(Classes.ComClassFactory);

                    //Pass a memory address to write to so we can marshal the COM interface.
                    IntPtr hComObjAddress = Marshal.AllocHGlobal(IntPtr.Size);

                    _ClassFactoryInstance = NewAppDomain(comInfo).CreateInstanceFromAndUnwrap(
                        type.Assembly.Location,      //Changed from type.Assembly.FullName - specify path instead of class name
                        type.FullName,
                        true,
                        BindingFlags.Default,
                        null,
                        new object[] { rclsid, hComObjAddress },
                        null,
                        null);


                    IntPtr comMarshalDirect = Marshal.GetComInterfaceForObject(_ClassFactoryInstance, typeof(IClassFactory));
                    IntPtr comObjectAddr    = Marshal.ReadIntPtr(hComObjAddress);

                    //Call to DllClassObject is requesting IClassFactory.
                    ppv = comObjectAddr;

                    Marshal.FreeHGlobal(hComObjAddress);

                    return(IntPtr.Zero); //S_OK
                }
                else
                {
                    return(new IntPtr(ComHelper.E_NOINTERFACE)); //CLASS_E_CLASSNOTAVAILABLE
                }
            }
            catch
            {
                return(new IntPtr(ComHelper.E_NOINTERFACE)); //CLASS_E_CLASSNOTAVAILABLE
            }
        }