void IDisposable.Dispose()
        {
            if (disposed)
            {
                return;
            }

            if (domain == null)
            {
                if (assemblyManager != null)
                {
                    assemblyManager.Dispose();
                    assemblyManager = null;
                }
            }
            else
            {
                Debug.Assert(assemblyManager != null);
                assemblyManager.Dispose();

                if (IsSafeToUnloadDomain)
                {
                    AppDomain.Unload(domain);
                }

                assemblyManager = null;
                domain          = null;
            }

            disposed = true;
        }
        void IDisposable.Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_domain == null)
            {
                if (_assemblyManager != null)
                {
                    _assemblyManager.Dispose();
                    _assemblyManager = null;
                }
            }
            else
            {
                Debug.Assert(_assemblyManager != null);
                _assemblyManager.Dispose();

                if (IsSafeToUnloadDomain)
                {
                    AppDomain.Unload(_domain);
                }

                _assemblyManager = null;
                _domain          = null;
            }

            _disposed = true;
        }
        void IDisposable.Dispose()
        {
            if (disposed)
            {
                return;
            }

            if (domain == null)
            {
                if (assemblyManager != null)
                {
                    assemblyManager.Dispose();

                    assemblyManager = null;
                }
            }
            else
            {
                // KevinH - I'm adding this for debugging...we seem to be getting to AppDomain.Unload when we shouldn't
                // (causing intermittant failures on the build machine).  We should never be creating a separate
                // AppDomain without its own assemblyManager.
                if (assemblyManager == null)
                {
                    throw new InvalidOperationException("assemblyManager should never be null if a remote domain was created");
                }
                else
                {
                    assemblyManager.Dispose();

                    if (IsSafeToUnloadDomain)
                    {
                        AppDomain.Unload(domain);
                    }

                    assemblyManager = null;
                }

                domain = null;
            }

            disposed = true;
        }