private string GetConfigurationElementName()
        {
            string name = string.Empty;
            ExtensionElementCollection elements = null;
            Type thisType = this.ThisType;
            ContextInformation containingEvaluationContext = this.ContainingEvaluationContext;

            if (containingEvaluationContext == null)
            {
                containingEvaluationContext = ConfigurationHelpers.GetEvaluationContext(this);
            }
            if (string.IsNullOrEmpty(this.extensionCollectionName))
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, 0x8001b, System.ServiceModel.SR.GetString("TraceCodeExtensionCollectionNameNotFound"), this, (Exception)null);
                }
                elements = ExtensionsSection.UnsafeLookupAssociatedCollection(this.ThisType, containingEvaluationContext, out this.extensionCollectionName);
            }
            else
            {
                elements = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, containingEvaluationContext);
            }
            if (elements == null)
            {
                if (string.IsNullOrEmpty(this.extensionCollectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigNoExtensionCollectionAssociatedWithType", new object[] { thisType.AssemblyQualifiedName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionCollectionNotFound", new object[] { this.extensionCollectionName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            for (int i = 0; i < elements.Count; i++)
            {
                ExtensionElement element = elements[i];
                if (element.Type.Equals(thisType.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    name = element.Name;
                    break;
                }
                Type type = Type.GetType(element.Type, false);
                if ((null != type) && thisType.Equals(type))
                {
                    name = element.Name;
                    break;
                }
            }
            if (string.IsNullOrEmpty(name))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigExtensionTypeNotRegisteredInCollection", new object[] { thisType.AssemblyQualifiedName, this.extensionCollectionName }), base.ElementInformation.Source, base.ElementInformation.LineNumber));
            }
            return(name);
        }
        string GetConfigurationElementName()
        {
            string configurationElementName       = String.Empty;
            ExtensionElementCollection collection = null;
            Type extensionSectionType             = ThisType;

            ContextInformation evaluationContext = this.ContainingEvaluationContext;

            if (evaluationContext == null)
            {
                evaluationContext = ConfigurationHelpers.GetEvaluationContext(this);
            }

            if (String.IsNullOrEmpty(this.extensionCollectionName))
            {
#if DESKTOP
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.ExtensionCollectionNameNotFound,
                                            SR.GetString(SR.TraceCodeExtensionCollectionNameNotFound),
                                            this,
                                            (Exception)null);
                }
#endif

                collection = ExtensionsSection.UnsafeLookupAssociatedCollection(ThisType, evaluationContext, out this.extensionCollectionName);
            }
            else
            {
                collection = ExtensionsSection.UnsafeLookupCollection(this.extensionCollectionName, evaluationContext);
            }

            if (null == collection)
            {
                if (String.IsNullOrEmpty(this.extensionCollectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigNoExtensionCollectionAssociatedWithType,
                                                                                                                            extensionSectionType.AssemblyQualifiedName),
                                                                                                               this.ElementInformation.Source,
                                                                                                               this.ElementInformation.LineNumber));
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionCollectionNotFound,
                                                                                                                            this.extensionCollectionName),
                                                                                                               this.ElementInformation.Source,
                                                                                                               this.ElementInformation.LineNumber));
                }
            }

            for (int i = 0; i < collection.Count; i++)
            {
                ExtensionElement collectionElement = collection[i];

                // Optimize for assembly qualified names.
                if (collectionElement.Type.Equals(extensionSectionType.AssemblyQualifiedName, StringComparison.Ordinal))
                {
                    configurationElementName = collectionElement.Name;
                    break;
                }

                // Check type directly for the case that the extension is registered with something less than
                // an full assembly qualified name.
                Type collectionElementType = Type.GetType(collectionElement.Type, false);
                if (null != collectionElementType && extensionSectionType.Equals(collectionElementType))
                {
                    configurationElementName = collectionElement.Name;
                    break;
                }
            }

            if (String.IsNullOrEmpty(configurationElementName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionTypeNotRegisteredInCollection,
                                                                                                                        extensionSectionType.AssemblyQualifiedName,
                                                                                                                        this.extensionCollectionName),
                                                                                                           this.ElementInformation.Source,
                                                                                                           this.ElementInformation.LineNumber));
            }

            return(configurationElementName);
        }