UnexpectedError() статический приватный Метод

static private UnexpectedError ( string methodName ) : InvalidOperationException
methodName string
Результат System.InvalidOperationException
Пример #1
0
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition,
                                                 ConfigurationAllowExeDefinition allowExeDefinition)
        {
            string allowedConfigPath;

            switch (allowExeDefinition)
            {
            case ConfigurationAllowExeDefinition.MachineOnly:
                allowedConfigPath = MachineConfigPath;
                break;

            case ConfigurationAllowExeDefinition.MachineToApplication:
                allowedConfigPath = ExeConfigPath;
                break;

            case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                allowedConfigPath = RoamingUserConfigPath;
                break;

            // MachineToLocalUser does not current have any definition restrictions
            case ConfigurationAllowExeDefinition.MachineToLocalUser:
                return(true);

            default:
                // If we have extended ConfigurationAllowExeDefinition
                // make sure to update this switch accordingly
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::IsDefinitionAllowed");
            }

            return(configPath.Length <= allowedConfigPath.Length);
        }
        public override bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
        {
            string str;

            switch (allowExeDefinition)
            {
            case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                str = "MACHINE/EXE/ROAMING_USER";
                break;

            case ConfigurationAllowExeDefinition.MachineToLocalUser:
                return(true);

            case ConfigurationAllowExeDefinition.MachineOnly:
                str = "MACHINE";
                break;

            case ConfigurationAllowExeDefinition.MachineToApplication:
                str = "MACHINE/EXE";
                break;

            default:
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::IsDefinitionAllowed");
            }
            return(configPath.Length <= str.Length);
        }
Пример #3
0
        public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition,
                                                     ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
        {
            if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
            {
                switch (allowExeDefinition)
                {
                case ConfigurationAllowExeDefinition.MachineOnly:
                    throw new ConfigurationErrorsException(
                              SR.Config_allow_exedefinition_error_machine, errorInfo);

                case ConfigurationAllowExeDefinition.MachineToApplication:
                    throw new ConfigurationErrorsException(
                              SR.Config_allow_exedefinition_error_application, errorInfo);

                case ConfigurationAllowExeDefinition.MachineToRoamingUser:
                    throw new ConfigurationErrorsException(
                              SR.Config_allow_exedefinition_error_roaminguser, errorInfo);

                default:
                    // If we have extended ConfigurationAllowExeDefinition
                    // make sure to update this switch accordingly
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed");
                }
            }
        }
Пример #4
0
        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            string str;
            string str2;

            this._typeConfigHost = typeConfigHost;
            this._hostInitConfigurationParams = hostInitConfigurationParams;
            this._configRoot = new InternalConfigRoot(this);
            IInternalConfigHost host  = (IInternalConfigHost)System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);
            IInternalConfigHost host2 = new UpdateConfigHost(host);

            ((IInternalConfigRoot)this._configRoot).Init(host2, true);
            host.InitForConfiguration(ref locationSubPath, out str, out str2, this._configRoot, hostInitConfigurationParams);
            if (!string.IsNullOrEmpty(locationSubPath) && !host2.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }
            if (string.IsNullOrEmpty(locationSubPath) != string.IsNullOrEmpty(str2))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }
            this._configRecord = (MgmtConfigurationRecord)this._configRoot.GetConfigRecord(str);
            if (!string.IsNullOrEmpty(locationSubPath))
            {
                this._configRecord = MgmtConfigurationRecord.Create(this._configRoot, this._configRecord, str2, locationSubPath);
            }
            this._configRecord.ThrowIfInitErrors();
        }
 public override Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext)
 {
     if (!this.IsFile(streamName))
     {
         throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::OpenStreamForWrite");
     }
     return(base.Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext));
 }
 public override void DeleteStream(string streamName)
 {
     if (!this.IsFile(streamName))
     {
         throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Delete");
     }
     base.Host.DeleteStream(streamName);
 }
Пример #7
0
        public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams)
        {
            try
            {
                ConfigurationFileMap fileMap = (ConfigurationFileMap)hostInitParams[0];
                _exePath = (string)hostInitParams[1];

                Host.Init(configRoot, hostInitParams);

                // Do not complete initialization in runtime config, to avoid expense of
                // loading user.config files that may not be required.
                _initComplete = configRoot.IsDesignTime;

                if ((fileMap != null) && !string.IsNullOrEmpty(_exePath))
                {
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
                }

                if (string.IsNullOrEmpty(_exePath))
                {
                    _exePath = null;
                }

                // Initialize the fileMap, if provided.
                if (fileMap != null)
                {
                    _fileMap = new ExeConfigurationFileMap();
                    if (!string.IsNullOrEmpty(fileMap.MachineConfigFilename))
                    {
                        _fileMap.MachineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
                    }

                    ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
                    if (exeFileMap != null)
                    {
                        if (!string.IsNullOrEmpty(exeFileMap.ExeConfigFilename))
                        {
                            _fileMap.ExeConfigFilename = Path.GetFullPath(exeFileMap.ExeConfigFilename);
                        }

                        if (!string.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename))
                        {
                            _fileMap.RoamingUserConfigFilename = Path.GetFullPath(exeFileMap.RoamingUserConfigFilename);
                        }

                        if (!string.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename))
                        {
                            _fileMap.LocalUserConfigFilename = Path.GetFullPath(exeFileMap.LocalUserConfigFilename);
                        }
                    }
                }
            }
            catch
            {
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
            }
        }
Пример #8
0
        public override void DeleteStream(string streamName)
        {
            // only support files, not URIs
            if (!IsFile(streamName))
            {
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Delete");
            }

            Host.DeleteStream(streamName);
        }
Пример #9
0
        public override Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext)
        {
            // only support files, not URIs
            if (!IsFile(streamName))
            {
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::OpenStreamForWrite");
            }

            return(Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext));
        }
Пример #10
0
        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstance(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            UpdateConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            // Now wrap in ImplicitMachineConfigHost so we can stub in a simple machine.config if needed.
            IInternalConfigHost implicitMachineConfigHost = new ImplicitMachineConfigHost(updateConfigHost);

            InternalConfigRoot configRoot = new InternalConfigRoot(this, updateConfigHost);

            ((IInternalConfigRoot)configRoot).Init(implicitMachineConfigHost, isDesignTime: true);

            // Set the configuration paths for this Configuration.
            //
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            string configPath, locationConfigPath;

            implicitMachineConfigHost.InitForConfiguration(
                ref locationSubPath,
                out configPath,
                out locationConfigPath,
                configRoot,
                hostInitConfigurationParams);

            if (!string.IsNullOrEmpty(locationSubPath) && !implicitMachineConfigHost.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (string.IsNullOrEmpty(locationSubPath) != string.IsNullOrEmpty(locationConfigPath))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord)configRoot.GetConfigRecord(configPath);

            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            if (!string.IsNullOrEmpty(locationSubPath))
            {
                _configRecord = MgmtConfigurationRecord.Create(
                    configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            // Throw if the config record we created contains global errors.
            _configRecord.ThrowIfInitErrors();
        }
        private ContextInformation _evalContext;                        // evaluation context

        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            _configRoot = new InternalConfigRoot();

            IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            _configRoot.Init(updateConfigHost, true);

            //
            // Set the configuration paths for this Configuration.
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            //
            string configPath, locationConfigPath;

            configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams);

            if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord)_configRoot.GetConfigRecord(configPath);

            //
            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            //
            if (!String.IsNullOrEmpty(locationSubPath))
            {
                _configRecord = MgmtConfigurationRecord.Create(
                    _configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            //
            // Throw if the config record we created contains global errors.
            //
            _configRecord.ThrowIfInitErrors();
        }
 public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams)
 {
     try
     {
         ConfigurationFileMap map = (ConfigurationFileMap)hostInitParams[0];
         this._exePath = (string)hostInitParams[1];
         base.Host.Init(configRoot, hostInitParams);
         this._initComplete = configRoot.IsDesignTime;
         if ((map != null) && !string.IsNullOrEmpty(this._exePath))
         {
             throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
         }
         if (string.IsNullOrEmpty(this._exePath))
         {
             this._exePath = null;
         }
         if (map != null)
         {
             this._fileMap = new ExeConfigurationFileMap();
             if (!string.IsNullOrEmpty(map.MachineConfigFilename))
             {
                 this._fileMap.MachineConfigFilename = Path.GetFullPath(map.MachineConfigFilename);
             }
             ExeConfigurationFileMap map2 = map as ExeConfigurationFileMap;
             if (map2 != null)
             {
                 if (!string.IsNullOrEmpty(map2.ExeConfigFilename))
                 {
                     this._fileMap.ExeConfigFilename = Path.GetFullPath(map2.ExeConfigFilename);
                 }
                 if (!string.IsNullOrEmpty(map2.RoamingUserConfigFilename))
                 {
                     this._fileMap.RoamingUserConfigFilename = Path.GetFullPath(map2.RoamingUserConfigFilename);
                 }
                 if (!string.IsNullOrEmpty(map2.LocalUserConfigFilename))
                 {
                     this._fileMap.LocalUserConfigFilename = Path.GetFullPath(map2.LocalUserConfigFilename);
                 }
             }
         }
     }
     catch (SecurityException)
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_client_config_init_security"));
     }
     catch
     {
         throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
     }
 }
Пример #13
0
        // Serialization methods
        protected ConfigurationErrorsException(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
            string firstFilename;
            int    firstLine;
            int    count;
            string numPrefix;
            string currentType;
            Type   currentExceptionType;

            // Retrieve out members
            firstFilename = info.GetString(SERIALIZATION_PARAM_FILENAME);
            firstLine     = info.GetInt32(SERIALIZATION_PARAM_LINE);

            Init(firstFilename, firstLine);

            // Retrieve errors for _errors object
            count = info.GetInt32(SERIALIZATION_PARAM_ERROR_COUNT);

            if (count != 0)
            {
                _errors = new ConfigurationException[count];

                for (int i = 0; i < count; i++)
                {
                    numPrefix = i.ToString(CultureInfo.InvariantCulture);

                    currentType          = info.GetString(numPrefix + SERIALIZATION_PARAM_ERROR_TYPE);
                    currentExceptionType = Type.GetType(currentType, true);

                    // Only allow our exception types
                    if ((currentExceptionType != typeof(ConfigurationException)) &&
                        (currentExceptionType != typeof(ConfigurationErrorsException)))
                    {
                        throw ExceptionUtil.UnexpectedError("ConfigurationErrorsException");
                    }

                    _errors[i] = (ConfigurationException)
                                 info.GetValue(numPrefix + SERIALIZATION_PARAM_ERROR_DATA,
                                               currentExceptionType);
                }
            }
        }
 public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
 {
     if (!this.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition))
     {
         ConfigurationAllowExeDefinition definition = allowExeDefinition;
         if (definition != ConfigurationAllowExeDefinition.MachineOnly)
         {
             if (definition == ConfigurationAllowExeDefinition.MachineToApplication)
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_application"), errorInfo);
             }
             if (definition == ConfigurationAllowExeDefinition.MachineToRoamingUser)
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_roaminguser"), errorInfo);
             }
             throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed");
         }
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_machine"), errorInfo);
     }
 }
Пример #15
0
        protected ConfigurationErrorsException(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
            int firstLine;
            int count;

            // Retrieve out members
            string firstFilename = info.GetString(SerializationParamFilename);

            firstLine = info.GetInt32(SerializationParamLine);

            Init(firstFilename, firstLine);

            // Retrieve errors for _errors object
            count = info.GetInt32(SerializationParamErrorCount);

            if (count == 0)
            {
                return;
            }
            _errors = new ConfigurationException[count];

            for (int i = 0; i < count; i++)
            {
                string numPrefix = i.ToString(CultureInfo.InvariantCulture);

                string currentType          = info.GetString(numPrefix + SerializationParamErrorType);
                Type   currentExceptionType = Type.GetType(currentType, true);

                // Only allow our exception types
                if ((currentExceptionType != typeof(ConfigurationException)) &&
                    (currentExceptionType != typeof(ConfigurationErrorsException)))
                {
                    throw ExceptionUtil.UnexpectedError("ConfigurationErrorsException");
                }

                _errors[i] = (ConfigurationException)
                             info.GetValue(numPrefix + SerializationParamErrorData,
                                           currentExceptionType);
            }
        }
Пример #16
0
        protected ConfigurationErrorsException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            string filename = info.GetString("firstFilename");
            int    line     = info.GetInt32("firstLine");

            this.Init(filename, line);
            int num2 = info.GetInt32("count");

            if (num2 != 0)
            {
                this._errors = new ConfigurationException[num2];
                for (int i = 0; i < num2; i++)
                {
                    string str2 = i.ToString(CultureInfo.InvariantCulture);
                    Type   type = Type.GetType(info.GetString(str2 + "_errors_type"), true);
                    if ((type != typeof(ConfigurationException)) && (type != typeof(ConfigurationErrorsException)))
                    {
                        throw ExceptionUtil.UnexpectedError("ConfigurationErrorsException");
                    }
                    this._errors[i] = (ConfigurationException)info.GetValue(str2 + "_errors", type);
                }
            }
        }
Пример #17
0
        public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams)
        {
            try {
                ConfigurationFileMap fileMap = (ConfigurationFileMap)hostInitParams[0];
                _exePath = (string)hostInitParams[1];

                Host.Init(configRoot, hostInitParams);

                // Do not complete initialization in runtime config, to avoid expense of
                // loading user.config files that may not be required.
                _initComplete = configRoot.IsDesignTime;

                if (fileMap != null && !String.IsNullOrEmpty(_exePath))
                {
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
                }

                if (String.IsNullOrEmpty(_exePath))
                {
                    _exePath = null;
                }

                // Initialize the fileMap, if provided.
                if (fileMap != null)
                {
                    _fileMap = new ExeConfigurationFileMap();
                    if (!String.IsNullOrEmpty(fileMap.MachineConfigFilename))
                    {
                        _fileMap.MachineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
                    }

                    ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
                    if (exeFileMap != null)
                    {
                        if (!String.IsNullOrEmpty(exeFileMap.ExeConfigFilename))
                        {
                            _fileMap.ExeConfigFilename = Path.GetFullPath(exeFileMap.ExeConfigFilename);
                        }

                        if (!String.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename))
                        {
                            _fileMap.RoamingUserConfigFilename = Path.GetFullPath(exeFileMap.RoamingUserConfigFilename);
                        }

                        if (!String.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename))
                        {
                            _fileMap.LocalUserConfigFilename = Path.GetFullPath(exeFileMap.LocalUserConfigFilename);
                        }
                    }
                }
            }
            catch (SecurityException) {
                // Lets try to give them some information telling them
                // they don't have enough security privileges
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Config_client_config_init_security));
            }
            catch {
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
            }
        }