internal void FlushForWriteCompleted()
        {
#if !FEATURE_PAL // FEATURE_PAL does not enable COM
            if (_IsDirty && _MemoryStream != null)
            {
                WindowsImpersonationContext wiContext = null;

                try
                {
                    ////////////////////////////////////////////////////////////
                    // Step 1: Set the impersonation if required
                    if (_Identity != null)
                    {
                        wiContext = _Identity.Impersonate();
                    }

                    try
                    {
                        IRemoteWebConfigurationHostServer remoteSrv = RemoteWebConfigurationHost.CreateRemoteObject(_Server, _Username, _Domain, _Password);
                        try
                        {
                            remoteSrv.WriteData(_FileName, _TemplateFileName, _MemoryStream.ToArray(), ref _ReadTime);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            while (Marshal.ReleaseComObject(remoteSrv) > 0)
                            {
                            }
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (wiContext != null)
                        {
                            wiContext.Undo();
                        }
                    }
                }
                catch
                {
                    throw;
                }

                _MemoryStream.Flush();
                _IsDirty = false;
            }
#else // !FEATURE_PAL
            throw new NotSupportedException();
#endif // !FEATURE_PAL
        }
 internal void FlushForWriteCompleted()
 {
     if (this._IsDirty && (this._MemoryStream != null))
     {
         WindowsImpersonationContext context = null;
         try
         {
             if (this._Identity != null)
             {
                 context = this._Identity.Impersonate();
             }
             try
             {
                 IRemoteWebConfigurationHostServer o = RemoteWebConfigurationHost.CreateRemoteObject(this._Server, this._Username, this._Domain, this._Password);
                 try
                 {
                     o.WriteData(this._FileName, this._TemplateFileName, this._MemoryStream.ToArray(), ref this._ReadTime);
                 }
                 catch
                 {
                     throw;
                 }
                 finally
                 {
                     while (Marshal.ReleaseComObject(o) > 0)
                     {
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 if (context != null)
                 {
                     context.Undo();
                 }
             }
         }
         catch
         {
             throw;
         }
         this._MemoryStream.Flush();
         this._IsDirty = false;
     }
 }