// Constructors

        /// <summary>
        /// Initializes a new instance of this type.
        /// </summary>
        /// <exception cref="SecurityException">Only one ancestor of each instance
        /// of this generic type is allowed.</exception>
        protected internal SimpleScope()
        {
            if (allowedType == null)
            {
                lock (@lock) if (allowedType == null)
                    {
                        allowedType = GetType();
                    }
            }
            if (allowedType != GetType())
            {
                throw new SecurityException(
                          Strings.ExOnlyOneAncestorOfEachInstanceOfThisGenericTypeIsAllowed);
            }
            outer = currentAsync.Value;
            currentAsync.Value = this;
        }
        /// <inheritdoc/>
        /// <exception cref="InvalidOperationException">Scope can't be disposed.</exception>
        public void Dispose()
        {
            bool      bStop = false;
            Exception error = null;

            while (!bStop)
            {
                try {
                    if (currentAsync == null)
                    {
                        bStop = true;
                        throw new InvalidOperationException(Strings.ExScopeCantBeDisposed);
                    }
                    else if (currentAsync.Value == this)
                    {
                        bStop = true;
                        currentAsync.Value.Dispose(true);
                    }
                    else
                    {
                        currentAsync.Value.Dispose();
                    }
                }
                catch (Exception e) {
                    if (error == null)
                    {
                        error = e;
                    }
                    try {
                        CoreLog.Error(e, Strings.LogScopeDisposeError);
                    }
                    catch {}
                }
            }
            currentAsync.Value = outer;
            outer = null;
            if (error != null)
            {
                throw error;
            }
        }