Наследование: IConfigErrorInfo
        internal SectionInput(SectionXmlInfo sectionXmlInfo, List<ConfigurationException> errors) {
            _sectionXmlInfo = sectionXmlInfo;
            _errors = errors;

            _result = s_unevaluated;
            _resultRuntimeObject = s_unevaluated;
        }
Пример #2
0
        internal SectionInput(SectionXmlInfo sectionXmlInfo, List <ConfigurationException> errors)
        {
            _sectionXmlInfo = sectionXmlInfo;
            _errors         = errors;

            _result = s_unevaluated;
            _resultRuntimeObject = s_unevaluated;
        }
Пример #3
0
        internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord,
                                                         FactoryRecord factoryRecord, SectionRecord sectionRecord)
        {
            _flags[FlagAttached] = true;

            // factory info
            ConfigKey                            = factoryRecord.ConfigKey;
            Name                                 = factoryRecord.Name;
            _typeName                            = factoryRecord.FactoryTypeName;
            _allowDefinition                     = factoryRecord.AllowDefinition;
            _allowExeDefinition                  = factoryRecord.AllowExeDefinition;
            _flags[FlagAllowLocation]            = factoryRecord.AllowLocation;
            _flags[FlagRestartOnExternalChanges] = factoryRecord.RestartOnExternalChanges;
            _flags[FlagRequirePermission]        = factoryRecord.RequirePermission;
            _overrideModeDefault                 = factoryRecord.OverrideModeDefault;

            if (factoryRecord.IsUndeclared)
            {
                _flags[FlagIsUndeclared]        = true;
                _flags[FlagDeclared]            = false;
                _flags[FlagDeclarationRequired] = false;
            }
            else
            {
                _flags[FlagIsUndeclared]        = false;
                _flags[FlagDeclared]            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
                _flags[FlagDeclarationRequired] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
            }

            // section info
            _flags[FlagLocationLocked] = sectionRecord.Locked;
            _flags[FlagChildrenLocked] = sectionRecord.LockChildren;
            _flags[FlagChildrenLockWithoutFileInput] = sectionRecord.LockChildrenWithoutFileInput;

            if (sectionRecord.HasFileInput)
            {
                SectionInput fileInput = sectionRecord.FileInput;

                _flags[FlagProtectionProviderDetermined] = fileInput.IsProtectionProviderDetermined;
                _protectionProvider = fileInput.ProtectionProvider;

                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;

                _configSource                  = sectionXmlInfo.ConfigSource;
                ConfigSourceStreamName         = sectionXmlInfo.ConfigSourceStreamName;
                _overrideMode                  = sectionXmlInfo.OverrideModeSetting;
                _flags[FlagInheritInChildApps] = !sectionXmlInfo.SkipInChildApps;
                ProtectionProviderName         = sectionXmlInfo.ProtectionProviderName;
            }
            else
            {
                _flags[FlagProtectionProviderDetermined] = false;
                _protectionProvider = null;
            }

            // element context information
            _configurationSection.AssociateContext(configRecord);
        }
Пример #4
0
 internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord)
 {
     this._flags[1]            = true;
     this._configKey           = factoryRecord.ConfigKey;
     this._group               = factoryRecord.Group;
     this._name                = factoryRecord.Name;
     this._typeName            = factoryRecord.FactoryTypeName;
     this._allowDefinition     = factoryRecord.AllowDefinition;
     this._allowExeDefinition  = factoryRecord.AllowExeDefinition;
     this._flags[8]            = factoryRecord.AllowLocation;
     this._flags[0x10]         = factoryRecord.RestartOnExternalChanges;
     this._flags[0x20]         = factoryRecord.RequirePermission;
     this._overrideModeDefault = factoryRecord.OverrideModeDefault;
     if (factoryRecord.IsUndeclared)
     {
         this._flags[0x2000] = true;
         this._flags[2]      = false;
         this._flags[4]      = false;
     }
     else
     {
         this._flags[0x2000] = false;
         this._flags[2]      = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
         this._flags[4]      = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
     }
     this._flags[0x40]   = sectionRecord.Locked;
     this._flags[0x80]   = sectionRecord.LockChildren;
     this._flags[0x4000] = sectionRecord.LockChildrenWithoutFileInput;
     if (sectionRecord.HasFileInput)
     {
         SectionInput fileInput = sectionRecord.FileInput;
         this._flags[0x800]       = fileInput.IsProtectionProviderDetermined;
         this._protectionProvider = fileInput.ProtectionProvider;
         SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
         this._configSource           = sectionXmlInfo.ConfigSource;
         this._configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
         this._overrideMode           = sectionXmlInfo.OverrideModeSetting;
         this._flags[0x100]           = !sectionXmlInfo.SkipInChildApps;
         this._protectionProviderName = sectionXmlInfo.ProtectionProviderName;
     }
     else
     {
         this._flags[0x800]       = false;
         this._protectionProvider = null;
     }
     this._configurationSection.AssociateContext(configRecord);
 }
        private List <ConfigurationException> _errors; // errors

        internal LocationSectionRecord(SectionXmlInfo sectionXmlInfo, List <ConfigurationException> errors)
        {
            SectionXmlInfo = sectionXmlInfo;
            _errors        = errors;
        }
Пример #6
0
        private List<ConfigurationException> _errors; // errors

        internal LocationSectionRecord(SectionXmlInfo sectionXmlInfo, List<ConfigurationException> errors)
        {
            SectionXmlInfo = sectionXmlInfo;
            _errors = errors;
        }
        // After the config file has been written out, update the section records
        // to reflect changes that were made in the config file.
        private void UpdateRecords() {
            if (_factoryRecords != null) {
                foreach (FactoryRecord factoryRecord in _factoryRecords.Values) {
                    // Update stream information
                    if (String.IsNullOrEmpty(factoryRecord.Filename)) {
                        factoryRecord.Filename = ConfigStreamInfo.StreamName;
                    }

                    factoryRecord.LineNumber = 0;

                    ConfigurationSection configSection = GetConfigSection(factoryRecord.ConfigKey);
                    if (configSection != null) {
                        if (configSection.SectionInformation.Type != null) {
                            factoryRecord.FactoryTypeName = configSection.SectionInformation.Type;
                        }

                        factoryRecord.AllowLocation = configSection.SectionInformation.AllowLocation;
                        factoryRecord.RestartOnExternalChanges = configSection.SectionInformation.RestartOnExternalChanges;
                        factoryRecord.RequirePermission = configSection.SectionInformation.RequirePermission;
                        factoryRecord.AllowDefinition = configSection.SectionInformation.AllowDefinition;
                        factoryRecord.AllowExeDefinition = configSection.SectionInformation.AllowExeDefinition;
                    }
                }
            }

            if (_sectionRecords != null) {
                string definitionConfigPath = (IsLocationConfig) ? _parent.ConfigPath : ConfigPath;
                foreach (SectionRecord sectionRecord in _sectionRecords.Values) {
                    string configSource;
                    string configSourceStreamName;
                    object configSourceStreamVersion;
                    ConfigurationSection configSection;

                    if (sectionRecord.HasResult) {
                        configSection = (ConfigurationSection) sectionRecord.Result;
                        configSource = configSection.SectionInformation.ConfigSource;
                        if (String.IsNullOrEmpty(configSource)) {
                            configSource = null;
                        }

                        configSourceStreamName = configSection.SectionInformation.ConfigSourceStreamName;
                        if (String.IsNullOrEmpty(configSourceStreamName)) {
                            configSourceStreamName = null;
                        }
                    }
                    else {
                        configSection = null;
                        configSource = null;
                        configSourceStreamName = null;

                        // If there is no result, then the only way there could be a
                        // section record is:
                        // 1. For there to be input in the file.
                        // 2. A location tag applies to this record
                        Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs");

                        // Note that if it's a location input, we don't need to monitor the configSource because
                        // that stream is monitored by one of our parent's config record
                        if (sectionRecord.HasFileInput) {
                            SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                            configSource = sectionXmlInfo.ConfigSource;
                            configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
                        }
                    }

                    if (!String.IsNullOrEmpty(configSource)) {
                        configSourceStreamVersion = MonitorStream(sectionRecord.ConfigKey, configSource, configSourceStreamName);
                    }
                    else {
                        configSourceStreamVersion = null;
                    }

                    if (!sectionRecord.HasResult) {
                        Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs");

                        // Note that if it's a location input, we don't need to monitor the configSource because
                        // that stream is monitored by one of our parent's config record
                        if (sectionRecord.HasFileInput) {
                            SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                            sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion;
                            sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion;
                        }
                    }
                    else {
                        configSection.SectionInformation.RawXml = null;
                        bool addUpdate = sectionRecord.AddUpdate;
                        sectionRecord.AddUpdate = false;

                        if (addUpdate) {
                            SectionInput fileInput = sectionRecord.FileInput;
                            if (fileInput == null) {
                                SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(
                                        sectionRecord.ConfigKey, definitionConfigPath, _configPath, _locationSubPath,
                                        ConfigStreamInfo.StreamName, 0, ConfigStreamInfo.StreamVersion, null,
                                        configSource, configSourceStreamName, configSourceStreamVersion,
                                        configSection.SectionInformation.ProtectionProviderName,
                                        configSection.SectionInformation.OverrideModeSetting,
                                        !configSection.SectionInformation.InheritInChildApplications);

                                fileInput = new SectionInput(sectionXmlInfo, null);
                                fileInput.Result = configSection;
                                fileInput.ResultRuntimeObject = configSection;
                                sectionRecord.AddFileInput(fileInput);
                            }
                            else {
                                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
                                sectionXmlInfo.LineNumber = 0;
                                sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion;

                                sectionXmlInfo.RawXml = null;
                                sectionXmlInfo.ConfigSource = configSource;
                                sectionXmlInfo.ConfigSourceStreamName = configSourceStreamName;
                                sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion;
                                sectionXmlInfo.ProtectionProviderName = configSection.SectionInformation.ProtectionProviderName;
                                sectionXmlInfo.OverrideModeSetting = configSection.SectionInformation.OverrideModeSetting;
                                sectionXmlInfo.SkipInChildApps = !configSection.SectionInformation.InheritInChildApplications;
                            }

                            fileInput.ProtectionProvider = configSection.SectionInformation.ProtectionProvider;
                        }

                        try {
                            configSection.ResetModified();
                        }
                        catch (Exception e) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, sectionRecord.ConfigKey), e, ConfigStreamInfo.StreamName, 0);
                        }
                    }
                }
            }

            // Copy remaining stream updates, which correspond to streams used by location sections
            foreach (StreamInfo streamInfo in _streamInfoUpdates.Values) {
                if (!ConfigStreamInfo.StreamInfos.Contains(streamInfo.StreamName)) {
                    MonitorStream(streamInfo.SectionName, streamInfo.ConfigSource, streamInfo.StreamName);
                }
            }

            // reinitialize _streamInfoUpdates
            InitStreamInfoUpdates();

            // Update namespace value
            _flags[ NamespacePresentInFile ] = _flags[ NamespacePresentCurrent ];

            // You only have one chance to force the location config, now you
            // will have to recreate the object
            _flags[ ForceLocationWritten ]   = false;
            _flags[ SuggestLocationRemoval ] = false;

            // Handle removed location sections
            if (!IsLocationConfig && _locationSections != null && _removedSections != null && _removedSections.Count > 0) {
                int i = 0;
                while (i < _locationSections.Count) {
                    LocationSectionRecord locationSectionRecord = (LocationSectionRecord) _locationSections[i];
                    if (_removedSections.Contains(locationSectionRecord.ConfigKey)) {
                        _locationSections.RemoveAt(i);
                    }
                    else {
                        i++;
                    }
                }
            }

            _removedSections = null;
            _removedSectionGroups = null;
        }
        // Recursively clear the result.
        // If forceEvaluation == true, force a rescan of the config file to find
        // the section.
        // Requires the hierarchy lock to be acquired (hl)
        internal void hlClearResultRecursive(string configKey, bool forceEvaluatation) {
            SectionRecord sectionRecord;

            // Refresh it's factory Record
            RefreshFactoryRecord(configKey);

            // Clear any stored result in the section
            sectionRecord = GetSectionRecord(configKey, false);
            if (sectionRecord != null) {
                sectionRecord.ClearResult();

                sectionRecord.ClearRawXml();
            }

            //
            // If we need to reevaluate, add a dummy file input so 
            // that we open the file on the next evaluation
            //
            if (forceEvaluatation && !IsInitDelayed && !String.IsNullOrEmpty(ConfigStreamInfo.StreamName)) {
                if (_flags[SupportsPath]) {
                    throw ExceptionUtil.UnexpectedError("BaseConfigurationRecord::hlClearResultRecursive");
                }

                FactoryRecord factoryRecord = FindFactoryRecord(configKey, false);
                if (factoryRecord != null && !factoryRecord.IsGroup) {
                    configKey = factoryRecord.ConfigKey;
                    sectionRecord = EnsureSectionRecord(configKey, false);
                    if (!sectionRecord.HasFileInput) {
                        SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(
                            configKey, _configPath, _configPath, null,
                            ConfigStreamInfo.StreamName, 0, null, null, 
                            null, null, null, 
                            null, false, false);

                        SectionInput fileInput = new SectionInput(sectionXmlInfo, null);
                        sectionRecord.AddFileInput(fileInput);
                    }
                }
            }

            // Recurse
            if (_children != null) {
                IEnumerable children = _children.Values;
                foreach (BaseConfigurationRecord child in children) {
                    child.hlClearResultRecursive(configKey, forceEvaluatation);
                }
            }
        }
        private void ScanSectionsRecursive(
                XmlUtil xmlUtil, string parentConfigKey, bool inLocation, string locationSubPath, 
                bool lockChildren, bool skipInChildApps) {

            // discard any accumulated local errors
            xmlUtil.SchemaErrors.ResetLocalErrors();

            int depth;

            // only move to child nodes when not on first level (we've already passed the first <configsections>)
            if (parentConfigKey.Length == 0 && !inLocation) {
                depth = 0;
            }
            else {
                depth = xmlUtil.Reader.Depth;
                xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
            }

            while (xmlUtil.Reader.Depth == depth + 1) {

                string tagName = xmlUtil.Reader.Name;

                //
                // Check for reserved elements before looking up the factory,
                // which may have the same name if it is in error.
                //
                if (tagName == KEYWORD_CONFIGSECTIONS) {
                    // Error: duplicate <configSections> tag, or <configSections> not the first tag under <configuration>
                    xmlUtil.SchemaErrors.AddError(
                            new ConfigurationErrorsException(SR.GetString(SR.Config_client_config_too_many_configsections_elements, tagName), xmlUtil),
                            ExceptionAction.NonSpecific);

                    xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
                    continue;
                }

                if (tagName == KEYWORD_LOCATION) {
                    if (parentConfigKey.Length > 0 || inLocation) {
                        // Error: <location> section not at top level
                        xmlUtil.SchemaErrors.AddError(
                                new ConfigurationErrorsException(SR.GetString(SR.Config_location_location_not_allowed), xmlUtil),
                                ExceptionAction.Global);

                        xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
                    }
                    else {
                        // Recurse into the location section
                        ScanLocationSection(xmlUtil);
                    }

                    continue;
                }

                string configKey = CombineConfigKey(parentConfigKey, tagName);
                FactoryRecord factoryRecord = FindFactoryRecord(configKey, true);


                if (factoryRecord == null) {
                    // 
                    //
                    if (!ClassFlags[ClassIgnoreLocalErrors]) {
                        xmlUtil.SchemaErrors.AddError(
                                new ConfigurationErrorsException(SR.GetString(SR.Config_unrecognized_configuration_section, configKey), xmlUtil),
                                ExceptionAction.Local);
                    }

                    VerifySectionName(tagName, xmlUtil, ExceptionAction.Local, false);

                    factoryRecord = new FactoryRecord(
                            configKey, 
                            parentConfigKey,
                            tagName,
                            typeof(DefaultSection).AssemblyQualifiedName,
                            true,   // allowLocation
                            ConfigurationAllowDefinition.Everywhere,
                            ConfigurationAllowExeDefinition.MachineToRoamingUser,
                            true,   // restartOnExternalChanges
                            true,   // requirePermission
                            _flags[IsTrusted],
                            true,   // isUndeclared
                            null,
                            -1);

                    // Add any errors we may have encountered to the factory record,
                    // so that child config that also refer to this unrecognized section
                    // get the error.
                    factoryRecord.AddErrors(xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true));

                    // Add the factory to the list of factories
                    EnsureFactories()[configKey] = factoryRecord;
                }

                if (factoryRecord.IsGroup) {
                    //
                    // Section Group
                    //
                    if (factoryRecord.HasErrors) {
                        xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
                    }
                    else {
                        if (xmlUtil.Reader.AttributeCount > 0) {
                            while (xmlUtil.Reader.MoveToNextAttribute()) {
                                if (IsReservedAttributeName(xmlUtil.Reader.Name)) {
                                    xmlUtil.AddErrorReservedAttribute(ExceptionAction.NonSpecific);
                                }
                            }

                            xmlUtil.Reader.MoveToElement(); // if on an attribute move back to the element
                        }

                        // Recurse into group definition
                        ScanSectionsRecursive(xmlUtil, configKey, inLocation, locationSubPath, lockChildren, skipInChildApps);
                    }
                }
                else {
                    //
                    // Section
                    //
                    configKey = factoryRecord.ConfigKey;
                    string fileName = xmlUtil.Filename;
                    int lineNumber = xmlUtil.LineNumber;
                    string rawXml = null;
                    string configSource = null;
                    string configSourceStreamName = null;
                    object configSourceStreamVersion = null;
                    string protectionProviderName = null;
                    bool isSectionLocked = false;
                    bool positionedAtNextElement = false;
                    bool isFileInput = (locationSubPath == null);

                    if (!factoryRecord.HasErrors) {
                        // We have a valid factoryRecord for a section
                        if (inLocation && factoryRecord.AllowLocation == false) {
                            xmlUtil.SchemaErrors.AddError(
                                    new ConfigurationErrorsException(SR.GetString(SR.Config_section_cannot_be_used_in_location), xmlUtil), 
                                    ExceptionAction.Local);
                        }
    
                        // Verify correctness for file inputs.
                        if (isFileInput) {
                            // Verify that the section is unique
                            SectionRecord sectionRecord = GetSectionRecord(configKey, true);
                            if (sectionRecord != null && sectionRecord.HasFileInput) {
                                xmlUtil.SchemaErrors.AddError(
                                    new ConfigurationErrorsException(SR.GetString(SR.Config_sections_must_be_unique), xmlUtil),
                                    ExceptionAction.Local);
                            }

                            // Verify that the definition is allowed.
                            try {
                                VerifyDefinitionAllowed(factoryRecord, _configPath, xmlUtil);
                            }
                            catch (ConfigurationException ce) {
                                xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
                            }
                        }

                        // Verify that section is unlocked, both for file and location inputs.
                        try {
                            VerifySectionUnlocked(configKey, xmlUtil);
                        }
                        catch (ConfigurationException ce) {
                            isSectionLocked = true;
                            xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
                        }

                        // check for configSource or protectionProvider
                        if (xmlUtil.Reader.AttributeCount >= 1) {
                            // First do all the attributes reading without advancing the reader.
                            
                            string configSourceAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_CONFIGSOURCE);
                            if (configSourceAttribute != null) {
                                try {
                                    configSource = NormalizeConfigSource(configSourceAttribute, xmlUtil);
                                }
                                catch (ConfigurationException ce) {
                                    xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
                                }

                                if (xmlUtil.Reader.AttributeCount != 1) {
                                    // Error: elements with configSource should not have other attributes
                                    xmlUtil.SchemaErrors.AddError(
                                            new ConfigurationErrorsException(SR.GetString(SR.Config_source_syntax_error), xmlUtil), 
                                            ExceptionAction.Local);
                                }
                            }

                            string protectionProviderAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_PROTECTION_PROVIDER);
                            if (protectionProviderAttribute != null) {
                                try {
                                    protectionProviderName = ValidateProtectionProviderAttribute(protectionProviderAttribute, xmlUtil);
                                }
                                catch (ConfigurationException ce) {
                                    xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
                                }
                                
                                if (xmlUtil.Reader.AttributeCount != 1) {
                                    // Error: elements with protectionProvider should not have other attributes
                                    xmlUtil.SchemaErrors.AddError(
                                            new ConfigurationErrorsException(SR.GetString(SR.Protection_provider_syntax_error), xmlUtil), 
                                            ExceptionAction.Local);
                                }
                            }

                            // The 2nd part of the configSource check requires advancing the reader.
                            // Please note that this part should be done only AFTER all other attributes
                            // checking are done.
                            if (configSourceAttribute != null) {
                                if (!xmlUtil.Reader.IsEmptyElement) {
                                    while (xmlUtil.Reader.Read()) {
                                        XmlNodeType t = xmlUtil.Reader.NodeType;
                                        if (t == XmlNodeType.EndElement)
                                            break;

                                        if (t != XmlNodeType.Comment) {
                                            // Error: elements with configSource should not subelements other than comments
                                            xmlUtil.SchemaErrors.AddError(
                                                    new ConfigurationErrorsException(SR.GetString(SR.Config_source_syntax_error), xmlUtil),
                                                    ExceptionAction.Local);

                                            if (t == XmlNodeType.Element) {
                                                xmlUtil.StrictSkipToOurParentsEndElement(ExceptionAction.NonSpecific);
                                            }
                                            else {
                                                xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
                                            }

                                            positionedAtNextElement = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (configSource != null) {
                            try {
                                try {
                                    configSourceStreamName = Host.GetStreamNameForConfigSource(ConfigStreamInfo.StreamName, configSource);
                                }
                                catch (Exception e) {
                                    throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_source_invalid), e, xmlUtil);
                                }
                                ValidateUniqueConfigSource(configKey, configSourceStreamName, configSource, xmlUtil);
                                configSourceStreamVersion = MonitorStream(configKey, configSource, configSourceStreamName);
                            }
                            catch (ConfigurationException ex) {
                                xmlUtil.SchemaErrors.AddError(ex, ExceptionAction.Local);
                            }
                        }

                        //
                        // prefetch the raw xml
                        //
                        if (!xmlUtil.SchemaErrors.HasLocalErrors) {
                            if (configSource == null && ShouldPrefetchRawXml(factoryRecord)) {
                                Debug.Assert(!positionedAtNextElement, "!positionedAtNextElement");

                                rawXml = xmlUtil.CopySection();
                                if (xmlUtil.Reader.NodeType != XmlNodeType.Element) {
                                    xmlUtil.VerifyIgnorableNodeType(ExceptionAction.NonSpecific);
                                    xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
                                }

                                positionedAtNextElement = true;
                            }
                        }
                    }

                    // Get the list of errors before advancing the reader
                    List<ConfigurationException> localErrors = xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(isFileInput);

                    // advance the reader to the next element
                    if (!positionedAtNextElement) {
                        xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);                            
                    }

                    // Add the input either to:
                    // 1. The file input at the current config level, or
                    // 2. LocationSections, where it will be used in sub paths
                    bool addInput = true;

                    if (isFileInput) {
                        // If isFileInput==true, Input added will be used against this config level.
                        // Need to check if we need to skip it due to inheritInChildApplications.
                        
                        if (ShouldSkipDueToInheritInChildApplications(skipInChildApps)) {
                            addInput = false;
                        }
                    }
                    else {
                        if (!_flags[SupportsLocation]) {
                            // Skip if we have a location input but we don't support location tag.
                            addInput = false;
                        }
                    }
                    
                    if (addInput) {

                        string targetConfigPath = (locationSubPath == null) ? _configPath : null;

                        SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(
                                configKey, _configPath, targetConfigPath, locationSubPath,
                                fileName, lineNumber, ConfigStreamInfo.StreamVersion, rawXml, 
                                configSource, configSourceStreamName, configSourceStreamVersion,
                                protectionProviderName, lockChildren, skipInChildApps);

                        if (locationSubPath == null) {
                            //
                            // Add this file input to the section record
                            //

                            // We've already checked for locked above, so use skip the second check
                            // and set the locked bit.
                            SectionRecord sectionRecord = EnsureSectionRecordUnsafe(configKey, true);

                            Debug.Assert(!sectionRecord.Locked || isSectionLocked,
                                        "!sectionRecord.Locked || isSectionLocked");

                            if (isSectionLocked) {
                                sectionRecord.Locked = true;
                            }
                            
                            SectionInput fileInput = new SectionInput(sectionXmlInfo, localErrors);
                            sectionRecord.AddFileInput(fileInput);
                        }
                        else {
                            //
                            // Add this location input to this list of location sections
                            //
                            LocationSectionRecord locationSectionRecord = new LocationSectionRecord(sectionXmlInfo, localErrors);
                            EnsureLocationSections().Add(locationSectionRecord);
                        }
                    }
                }
            }
        }
        private ConfigXmlReader LoadConfigSource(string name, SectionXmlInfo sectionXmlInfo) {
            string configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
            
            try {
                using (Impersonate()) {
                    using (Stream stream = Host.OpenStreamForRead(configSourceStreamName)) {
                        if (stream == null) {
                            throw new ConfigurationErrorsException(
                                    SR.GetString(SR.Config_cannot_open_config_source, sectionXmlInfo.ConfigSource),
                                    sectionXmlInfo);
                        }

                        using (XmlUtil xmlUtil = new XmlUtil(stream, configSourceStreamName, true)) {
                            if (xmlUtil.Reader.Name != name) {
                                throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_file_format), xmlUtil);
                            }

                            // Check for protectionProvider
                            string protectionProviderAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_PROTECTION_PROVIDER);
                            if (protectionProviderAttribute != null) {
                                if (xmlUtil.Reader.AttributeCount != 1) {
                                    // Error: elements with protectionProvider should not have other attributes
                                    throw new ConfigurationErrorsException(SR.GetString(SR.Protection_provider_syntax_error), xmlUtil);
                                }
        
                                sectionXmlInfo.ProtectionProviderName = ValidateProtectionProviderAttribute(protectionProviderAttribute, xmlUtil);
                            }
                            
                            int lineOffset = xmlUtil.Reader.LineNumber;
                            string rawXml = xmlUtil.CopySection();

                            // Detect if there is any XML left over after the section
                            while (!xmlUtil.Reader.EOF) {
                                XmlNodeType t = xmlUtil.Reader.NodeType;
                                if (t != XmlNodeType.Comment) {
                                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_file_format), xmlUtil);
                                }

                                xmlUtil.Reader.Read();
                            }

                            ConfigXmlReader section = new ConfigXmlReader(rawXml, configSourceStreamName, lineOffset);
                            return section;
                        }
                    }
                }
            }
            catch {
                // Don't allow frames up the stack to run exception filters while impersonated.
                throw;
            }
        }
        private ConfigXmlReader FindSection(string [] keys, SectionXmlInfo sectionXmlInfo, out int lineNumber) {
            lineNumber = 0;
            ConfigXmlReader section = null;
            try {
                using (Impersonate()) {
                    using (Stream stream = Host.OpenStreamForRead(sectionXmlInfo.Filename)) {
                        if (       !_flags[SupportsRefresh] 
                                && (stream == null || HasStreamChanged(sectionXmlInfo.Filename, sectionXmlInfo.StreamVersion))) {

                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_file_has_changed), sectionXmlInfo.Filename, 0);
                        }

                        if (stream != null) {
                            using (XmlUtil xmlUtil = new XmlUtil(stream, sectionXmlInfo.Filename, true)) {
                                if (sectionXmlInfo.SubPath == null) {
                                    section = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
                                }
                                else {
                                    // search children of <configuration> for <location>
                                    xmlUtil.ReadToNextElement();
                                    while (xmlUtil.Reader.Depth > 0) {
                                        if (xmlUtil.Reader.Name == KEYWORD_LOCATION) {
                                            bool   locationValid = false;
                                            string locationSubPathAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_LOCATION_PATH);

                                            try {
                                                locationSubPathAttribute = NormalizeLocationSubPath(locationSubPathAttribute, xmlUtil);
                                                locationValid = true;
                                            }
                                            catch (ConfigurationException ce) {
                                                xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.NonSpecific);
                                            }

                                            if (locationValid &&
                                                 StringUtil.EqualsIgnoreCase(sectionXmlInfo.SubPath, locationSubPathAttribute)) {

                                                section = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
                                                if (section != null)
                                                    break;
                                            }
                                        }

                                        xmlUtil.SkipToNextElement();
                                    }
                                }

                                // Throw accumulated errors
                                ThrowIfParseErrors(xmlUtil.SchemaErrors);
                            }
                        }
                    }
                }
            }
            // Don't allow frames up the stack to run exception filters while impersonated.
            catch {
                throw;
            }


            return section;
        }
 private void UpdateRecords()
 {
     if (base._factoryRecords != null)
     {
         foreach (FactoryRecord record in base._factoryRecords.Values)
         {
             if (string.IsNullOrEmpty(record.Filename))
             {
                 record.Filename = base.ConfigStreamInfo.StreamName;
             }
             record.LineNumber = 0;
             ConfigurationSection configSection = this.GetConfigSection(record.ConfigKey);
             if (configSection != null)
             {
                 if (configSection.SectionInformation.Type != null)
                 {
                     record.FactoryTypeName = configSection.SectionInformation.Type;
                 }
                 record.AllowLocation = configSection.SectionInformation.AllowLocation;
                 record.RestartOnExternalChanges = configSection.SectionInformation.RestartOnExternalChanges;
                 record.RequirePermission = configSection.SectionInformation.RequirePermission;
                 record.AllowDefinition = configSection.SectionInformation.AllowDefinition;
                 record.AllowExeDefinition = configSection.SectionInformation.AllowExeDefinition;
             }
         }
     }
     if (base._sectionRecords != null)
     {
         string definitionConfigPath = base.IsLocationConfig ? base._parent.ConfigPath : base.ConfigPath;
         foreach (SectionRecord record2 in base._sectionRecords.Values)
         {
             string configSource;
             string configSourceStreamName;
             object obj2;
             ConfigurationSection result;
             if (record2.HasResult)
             {
                 result = (ConfigurationSection) record2.Result;
                 configSource = result.SectionInformation.ConfigSource;
                 if (string.IsNullOrEmpty(configSource))
                 {
                     configSource = null;
                 }
                 configSourceStreamName = result.SectionInformation.ConfigSourceStreamName;
                 if (string.IsNullOrEmpty(configSourceStreamName))
                 {
                     configSourceStreamName = null;
                 }
             }
             else
             {
                 result = null;
                 configSource = null;
                 configSourceStreamName = null;
                 if (record2.HasFileInput)
                 {
                     SectionXmlInfo sectionXmlInfo = record2.FileInput.SectionXmlInfo;
                     configSource = sectionXmlInfo.ConfigSource;
                     configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
                 }
             }
             if (!string.IsNullOrEmpty(configSource))
             {
                 obj2 = base.MonitorStream(record2.ConfigKey, configSource, configSourceStreamName);
             }
             else
             {
                 obj2 = null;
             }
             if (!record2.HasResult)
             {
                 if (record2.HasFileInput)
                 {
                     SectionXmlInfo info2 = record2.FileInput.SectionXmlInfo;
                     info2.StreamVersion = base.ConfigStreamInfo.StreamVersion;
                     info2.ConfigSourceStreamVersion = obj2;
                 }
             }
             else
             {
                 result.SectionInformation.RawXml = null;
                 bool addUpdate = record2.AddUpdate;
                 record2.AddUpdate = false;
                 if (addUpdate)
                 {
                     SectionInput fileInput = record2.FileInput;
                     if (fileInput == null)
                     {
                         SectionXmlInfo info3 = new SectionXmlInfo(record2.ConfigKey, definitionConfigPath, base._configPath, base._locationSubPath, base.ConfigStreamInfo.StreamName, 0, base.ConfigStreamInfo.StreamVersion, null, configSource, configSourceStreamName, obj2, result.SectionInformation.ProtectionProviderName, result.SectionInformation.OverrideModeSetting, !result.SectionInformation.InheritInChildApplications);
                         fileInput = new SectionInput(info3, null) {
                             Result = result,
                             ResultRuntimeObject = result
                         };
                         record2.AddFileInput(fileInput);
                     }
                     else
                     {
                         SectionXmlInfo info4 = fileInput.SectionXmlInfo;
                         info4.LineNumber = 0;
                         info4.StreamVersion = base.ConfigStreamInfo.StreamVersion;
                         info4.RawXml = null;
                         info4.ConfigSource = configSource;
                         info4.ConfigSourceStreamName = configSourceStreamName;
                         info4.ConfigSourceStreamVersion = obj2;
                         info4.ProtectionProviderName = result.SectionInformation.ProtectionProviderName;
                         info4.OverrideModeSetting = result.SectionInformation.OverrideModeSetting;
                         info4.SkipInChildApps = !result.SectionInformation.InheritInChildApplications;
                     }
                     fileInput.ProtectionProvider = result.SectionInformation.ProtectionProvider;
                 }
                 try
                 {
                     result.ResetModified();
                 }
                 catch (Exception exception)
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_exception_in_config_section_handler", new object[] { record2.ConfigKey }), exception, base.ConfigStreamInfo.StreamName, 0);
                 }
             }
         }
     }
     foreach (StreamInfo info5 in this._streamInfoUpdates.Values)
     {
         if (!base.ConfigStreamInfo.StreamInfos.Contains(info5.StreamName))
         {
             base.MonitorStream(info5.SectionName, info5.ConfigSource, info5.StreamName);
         }
     }
     this.InitStreamInfoUpdates();
     this._flags[0x200] = this._flags[0x4000000];
     this._flags[0x1000000] = false;
     this._flags[0x2000000] = false;
     if ((!base.IsLocationConfig && (base._locationSections != null)) && ((this._removedSections != null) && (this._removedSections.Count > 0)))
     {
         int index = 0;
         while (index < base._locationSections.Count)
         {
             LocationSectionRecord record3 = (LocationSectionRecord) base._locationSections[index];
             if (this._removedSections.Contains(record3.ConfigKey))
             {
                 base._locationSections.RemoveAt(index);
             }
             else
             {
                 index++;
             }
         }
     }
     this._removedSections = null;
     this._removedSectionGroups = null;
 }