ConfigurationErrorsException ConfigurationErrorsException ConfigurationErrorsException ConfigurationErrorsException Class

定義

構成エラーが発生したときにスローされる例外。The exception that is thrown when a configuration error has occurred.

public ref class ConfigurationErrorsException : System::Configuration::ConfigurationException
[System.Serializable]
public class ConfigurationErrorsException : System.Configuration.ConfigurationException
type ConfigurationErrorsException = class
    inherit ConfigurationException
Public Class ConfigurationErrorsException
Inherits ConfigurationException
継承
属性

次のコード例はカスタム セクションを作成し、生成、ConfigurationErrorsException例外のプロパティを変更するとします。The following code example creates a custom section and generates a ConfigurationErrorsException exception when it modifies its properties.

using System;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections;

namespace Samples.AspNet
{

    // Define a custom section.
    public sealed class CustomSection :
       ConfigurationSection
    {
        public CustomSection()
        {
        }

        [ConfigurationProperty("fileName", DefaultValue = "default.txt",
                    IsRequired = true, IsKey = false)]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
            MinLength = 1, MaxLength = 60)]
        public string FileName
        {
            get
            {
                return (string)this["fileName"];
            }
            set
            {
                this["fileName"] = value;
            }
        }

        [ConfigurationProperty("maxUsers", DefaultValue = (long)10,
            IsRequired = false)]
        [LongValidator(MinValue = 1, MaxValue = 100,
            ExcludeRange = false)]
        public long MaxUsers
        {
            get
            {
                return (long)this["maxUsers"];
            }
            set
            {
                this["maxUsers"] = value;
            }
        }

    }


    // Create the custom section and write it to
    // the configuration file.
    class UsingConfigurationErrorsException
    {
        // Create a custom section.
        static UsingConfigurationErrorsException()
        {
            // Get the application configuration file.
            System.Configuration.Configuration config =
                    ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // If the section does not exist in the configuration
            // file, create it and save it to the file.
            if (config.Sections["CustomSection"] == null)
            {
                CustomSection custSection = new CustomSection();
                config.Sections.Add("CustomSection", custSection);
                custSection =
                    config.GetSection("CustomSection") as CustomSection;
                custSection.SectionInformation.ForceSave = true;
                config.Save(ConfigurationSaveMode.Full);
            }
        }
        
        // Modify a custom section and cause configuration 
        // error exceptions.
        static void ModifyCustomSection()
        {

            try
            {
                // Get the application configuration file.
                System.Configuration.Configuration config =
                        ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                CustomSection custSection =
                   config.Sections["CustomSection"] as CustomSection;

                // Change the section properties.
                custSection.FileName = "newName.txt";
                
                // Cause an exception.
                custSection.MaxUsers = custSection.MaxUsers + 100;

                if (!custSection.ElementInformation.IsLocked)
                    config.Save();
                else
                    Console.WriteLine(
                        "Section was locked, could not update.");
            }
            catch (ConfigurationErrorsException err)
            {

                string msg = err.Message;
                Console.WriteLine("Message: {0}", msg);

                string fileName = err.Filename;
                Console.WriteLine("Filename: {0}", fileName);

                int lineNumber = err.Line;
                Console.WriteLine("Line: {0}", lineNumber.ToString());

                string bmsg = err.BareMessage;
                Console.WriteLine("BareMessage: {0}", bmsg);

                string source = err.Source;
                Console.WriteLine("Source: {0}", source);

                string st = err.StackTrace;
                Console.WriteLine("StackTrace: {0}", st);

            }
        }

        static void Main(string[] args)
        {
            ModifyCustomSection();
        }

    
    }
}
Imports System
Imports System.Configuration
Imports System.Collections.Specialized
Imports System.Collections



' Define a custom section.

NotInheritable Public Class CustomSection
    Inherits ConfigurationSection
    
    Public Sub New() 
    
    End Sub 'New
    
    
    <ConfigurationProperty("fileName", DefaultValue:="default.txt", IsRequired:=True, IsKey:=False), StringValidator(InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, MaxLength:=60)> _
    Public Property FileName() As String
        Get
            Return CStr(Me("fileName"))
        End Get
        Set(ByVal value As String)
            Me("fileName") = value
        End Set
    End Property
    
    
    <ConfigurationProperty("maxUsers", DefaultValue:=10, IsRequired:=False), LongValidator(MinValue:=1, MaxValue:=100, ExcludeRange:=False)> _
    Public Property MaxUsers() As Long
        Get
            Return Fix(Me("maxUsers"))
        End Get
        Set(ByVal value As Long)
            Me("maxUsers") = value
        End Set
    End Property
End Class 'CustomSection 


' Create the custom section and write it to
' the configuration file.

Class UsingConfigurationErrorsException
    
    ' Create a custom section.
    Shared Sub New()

        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' If the section does not exist in the configuration
        ' file, create it and save it to the file.
        If config.Sections("CustomSection") Is Nothing Then
            Dim custSection As New CustomSection()
            config.Sections.Add("CustomSection", custSection)
            custSection = config.GetSection("CustomSection")
            custSection.SectionInformation.ForceSave = True
            config.Save(ConfigurationSaveMode.Full)
        End If

    End Sub 'New
    
    
    ' Modify a custom section and cause configuration 
    ' error exceptions.
    Shared Sub ModifyCustomSection() 
        
        Try
            ' Get the application configuration file.
            Dim config _
            As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

            Dim custSection _
            As CustomSection = _
            config.Sections("CustomSection")
             
            ' Change the section properties.
            custSection.FileName = "newName.txt"
            
            ' Cause an exception.
            custSection.MaxUsers = _
            custSection.MaxUsers + 100
            
            If Not custSection.ElementInformation.IsLocked Then
                config.Save()
            Else
                Console.WriteLine( _
                "Section was locked, could not update.")
            End If
        Catch err As ConfigurationErrorsException
            
            Dim msg As String = err.Message
            Console.WriteLine("Message: {0}", msg)
            Dim fileName As String = err.Filename
            Console.WriteLine("Filename: {0}", _
            fileName)
            Dim lineNumber As Integer = err.Line
            Console.WriteLine("Line: {0}", _
            lineNumber.ToString())
            Dim bmsg As String = err.BareMessage
            Console.WriteLine("BareMessage: {0}", bmsg)
            Dim src As String = err.Source
            Console.WriteLine("Source: {0}", src)
            Dim st As String = err.StackTrace
            Console.WriteLine("StackTrace: {0}", st)
        End Try

    End Sub 'ModifyCustomSection

    Shared Sub Main(ByVal args() As String) 
        ModifyCustomSection()
    
    End Sub 'Main
End Class 'UsingConfigurationErrorsException 

次の例は、前の例で使用される構成の抜粋です。The following example is a configuration excerpt used by the previous example.

<?xml version="1.0" encoding="utf-8"?>  
<configuration>  
  <configSections>  
    <section name="CustomSection" type="Samples.AspNet.CustomSection,   
      ConfigurationErrorsException, Version=1.0.0.0, Culture=neutral,   
      PublicKeyToken=null" allowDefinition="Everywhere"   
      allowExeDefinition="MachineToApplication"   
      restartOnExternalChanges="true" />  
  </configSections>  
  <CustomSection fileName="default.txt" maxUsers="10" />  
</configuration>  

注釈

ConfigurationErrorsException構成情報の中にエラーが発生したときに例外がスローされます読み取りまたは書き込み。The ConfigurationErrorsException exception is thrown when any error occurs while configuration information is being read or written.

コンストラクター

ConfigurationErrorsException() ConfigurationErrorsException() ConfigurationErrorsException() ConfigurationErrorsException()

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(SerializationInfo, StreamingContext) ConfigurationErrorsException(SerializationInfo, StreamingContext) ConfigurationErrorsException(SerializationInfo, StreamingContext) ConfigurationErrorsException(SerializationInfo, StreamingContext)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String) ConfigurationErrorsException(String) ConfigurationErrorsException(String) ConfigurationErrorsException(String)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, Exception) ConfigurationErrorsException(String, Exception) ConfigurationErrorsException(String, Exception) ConfigurationErrorsException(String, Exception)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, Exception, String, Int32) ConfigurationErrorsException(String, Exception, String, Int32) ConfigurationErrorsException(String, Exception, String, Int32) ConfigurationErrorsException(String, Exception, String, Int32)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of a ConfigurationErrorsException class.

ConfigurationErrorsException(String, Exception, XmlNode) ConfigurationErrorsException(String, Exception, XmlNode) ConfigurationErrorsException(String, Exception, XmlNode) ConfigurationErrorsException(String, Exception, XmlNode)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, Exception, XmlReader) ConfigurationErrorsException(String, Exception, XmlReader) ConfigurationErrorsException(String, Exception, XmlReader) ConfigurationErrorsException(String, Exception, XmlReader)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, String, Int32) ConfigurationErrorsException(String, String, Int32) ConfigurationErrorsException(String, String, Int32) ConfigurationErrorsException(String, String, Int32)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, XmlNode) ConfigurationErrorsException(String, XmlNode) ConfigurationErrorsException(String, XmlNode) ConfigurationErrorsException(String, XmlNode)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

ConfigurationErrorsException(String, XmlReader) ConfigurationErrorsException(String, XmlReader) ConfigurationErrorsException(String, XmlReader) ConfigurationErrorsException(String, XmlReader)

ConfigurationErrorsException クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationErrorsException class.

プロパティ

BareMessage BareMessage BareMessage BareMessage

この構成上の例外がスローされた理由の記述を取得します。Gets a description of why this configuration exception was thrown.

Data Data Data Data

例外に関する追加のユーザー定義情報を提供する、キー/値ペアのコレクションを取得します。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
Errors Errors Errors Errors

この ConfigurationErrorsException 例外がスローされた理由の詳細なエラーのコレクションを取得します。Gets a collection of errors that detail the reasons this ConfigurationErrorsException exception was thrown.

Filename Filename Filename Filename

この構成上の例外がスローされる原因となった構成ファイルのパスを取得します。Gets the path to the configuration file that caused this configuration exception to be thrown.

HelpLink HelpLink HelpLink HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

現在の例外の原因となる Exception インスタンスを取得します。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Line Line Line Line

この構成上の例外がスローされた構成ファイル内の行番号を取得します。Gets the line number within the configuration file at which this configuration exception was thrown.

Message Message Message Message

この構成上の例外がスローされた理由の拡張された記述を取得します。Gets an extended description of why this configuration exception was thrown.

Source Source Source Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

呼び出し履歴で直前のフレームの文字列形式を取得します。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

現在の例外がスローされたメソッドを取得します。Gets the method that throws the current exception.

(Inherited from Exception)

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetFilename(XmlNode) GetFilename(XmlNode) GetFilename(XmlNode) GetFilename(XmlNode)

この構成上の例外がスローされたときに、内部 XmlNode オブジェクトの読み込み元であった構成ファイルのパスを取得します。Gets the path to the configuration file from which the internal XmlNode object was loaded when this configuration exception was thrown.

GetFilename(XmlReader) GetFilename(XmlReader) GetFilename(XmlReader) GetFilename(XmlReader)

この構成上の例外がスローされたときに、内部 XmlReader が読み取っていた構成ファイルのパスを取得します。Gets the path to the configuration file that the internal XmlReader was reading when this configuration exception was thrown.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetLineNumber(XmlNode) GetLineNumber(XmlNode) GetLineNumber(XmlNode) GetLineNumber(XmlNode)

この構成上の例外がスローされたときに、内部 XmlNode オブジェクトが表していた構成ファイル内の行番号を取得します。Gets the line number within the configuration file that the internal XmlNode object represented when this configuration exception was thrown.

GetLineNumber(XmlReader) GetLineNumber(XmlReader) GetLineNumber(XmlReader) GetLineNumber(XmlReader)

この構成上の例外がスローされたときに、内部 XmlReader オブジェクトが処理していた構成ファイル内の行番号を取得します。Gets the line number within the configuration file that the internal XmlReader object was processing when this configuration exception was thrown.

GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

ファイル名とこの構成上の例外が発生した行番号を使用して、SerializationInfo オブジェクトを設定します。Sets the SerializationInfo object with the file name and line number at which this configuration exception occurred.

GetType() GetType() GetType() GetType()

現在のインスタンスのランタイム型を取得します。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在の例外の文字列形式を作成して返します。Creates and returns a string representation of the current exception.

(Inherited from Exception)

イベント

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

適用対象