/// <summary>
        /// Load manifest to enable registry-free COM context.
        /// </summary>
        public void ActivateContext()
        {
            if (cookie != IntPtr.Zero || hActCtx != IntPtr.Zero)
            {
                return;
            }

            ActivationContextNativeMethods.ACTCTX context = new ActivationContextNativeMethods.ACTCTX();
            context.cbSize = Marshal.SizeOf(typeof(ActivationContextNativeMethods.ACTCTX));

            context.lpSource = this.manifestFilePath;

            hActCtx = ActivationContextNativeMethods.CreateActCtx(ref context);
            if (hActCtx == (IntPtr)(-1))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Fail to create registry-free COM context");
            }
            if (!ActivationContextNativeMethods.ActivateActCtx(hActCtx, out cookie))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Fail to activate registry-free COM context");
            }
        }
        /// <summary>
        /// Disable registry-free COM context.
        /// </summary>
        private void DeactivateContext()
        {
            if (cookie == IntPtr.Zero && hActCtx == IntPtr.Zero)
            {
                return;
            }

            try
            {
                ActivationContextNativeMethods.DeactivateActCtx(0, cookie);
                ActivationContextNativeMethods.ReleaseActCtx(hActCtx);
                cookie  = IntPtr.Zero;
                hActCtx = IntPtr.Zero;
            }
            catch (Exception ex)
            {
                // Log any exceptions during deactivation.
                if (EqtTrace.IsErrorEnabled)
                {
                    EqtTrace.Error(ex);
                }
            }
        }