private void Init()
 {
     if (this._MemoryStream == null)
     {
         byte[] buffer = 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
                 {
                     buffer = o.GetData(this._FileName, this._streamForWrite, out this._ReadTime);
                 }
                 finally
                 {
                     while (Marshal.ReleaseComObject(o) > 0)
                     {
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 if (context != null)
                 {
                     context.Undo();
                 }
             }
         }
         catch
         {
             throw;
         }
         if ((buffer == null) || (buffer.Length < 1))
         {
             this._MemoryStream = new MemoryStream();
         }
         else
         {
             this._MemoryStream = new MemoryStream(buffer.Length);
             this._MemoryStream.Write(buffer, 0, buffer.Length);
             this._MemoryStream.Position = 0L;
         }
     }
 }
        private void Init()
        {
#if !FEATURE_PAL // FEATURE_PAL does not enable COM
            if (_MemoryStream != null)
            {
                return;
            }

            byte[] buf = 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
                    {
                        // If we open the stream for writing, we only need to get the _ReadTime because
                        // we will create an empty memory stream for write.
                        buf = remoteSrv.GetData(_FileName, _streamForWrite, out _ReadTime);
                    }
                    finally
                    {
                        while (Marshal.ReleaseComObject(remoteSrv) > 0)
                        {
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (wiContext != null)
                    {
                        wiContext.Undo(); // revert impersonation
                    }
                }
            }
            catch
            {
                throw;
            }

            if (buf == null || buf.Length < 1)
            {
                _MemoryStream = new MemoryStream();
            }
            else
            {
                _MemoryStream = new MemoryStream(buf.Length);
                _MemoryStream.Write(buf, 0, buf.Length);
                _MemoryStream.Position = 0;
            }
#else // !FEATURE_PAL
            throw new NotSupportedException();
#endif // !FEATURE_PAL
        }