ConfigurationErrorsException 클래스

정의

구성 오류가 발생한 경우 throw되는 예외입니다.

public ref class ConfigurationErrorsException : System::Configuration::ConfigurationException
public class ConfigurationErrorsException : System.Configuration.ConfigurationException
[System.Serializable]
public class ConfigurationErrorsException : System.Configuration.ConfigurationException
type ConfigurationErrorsException = class
    inherit ConfigurationException
[<System.Serializable>]
type ConfigurationErrorsException = class
    inherit ConfigurationException
Public Class ConfigurationErrorsException
Inherits ConfigurationException
상속
특성

예제

다음 코드 예제에서는 사용자 지정 섹션을 ConfigurationErrorsException 만들고 해당 속성을 수정할 때 예외를 생성합니다.

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.Configuration
Imports System.Collections.Specialized
Imports System.Collections



' Define a custom section.

NotInheritable Public Class CustomSection
    Inherits ConfigurationSection
    
    Public Sub New() 
    
    End Sub
    
    
    <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


' 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
    
    
    ' 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

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

다음 예제는 이전 예제에서 사용한 구성 발췌입니다.

<?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 구성 정보를 읽거나 쓰는 동안 오류가 발생하면 예외가 throw됩니다.

생성자

ConfigurationErrorsException()

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(SerializationInfo, StreamingContext)
사용되지 않음.

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, Exception)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, Exception, String, Int32)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, Exception, XmlNode)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, Exception, XmlReader)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, String, Int32)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, XmlNode)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

ConfigurationErrorsException(String, XmlReader)

ConfigurationErrorsException 클래스의 새 인스턴스를 초기화합니다.

속성

BareMessage

이 구성 예외가 throw된 이유에 대한 설명을 가져옵니다.

BareMessage

이 구성 예외가 throw된 이유에 대한 설명을 가져옵니다.

(다음에서 상속됨 ConfigurationException)
Data

예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.

(다음에서 상속됨 Exception)
Errors

ConfigurationErrorsException 예외가 throw된 이유를 설명하는 오류 컬렉션을 가져옵니다.

Filename

이 구성 예외를 throw시킨 구성 파일에 대한 경로를 가져옵니다.

HelpLink

이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
HResult

특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
InnerException

현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.

(다음에서 상속됨 Exception)
Line

이 구성 예외가 throw된 구성 파일의 줄 번호를 가져옵니다.

Message

이 구성 예외가 throw된 이유에 대한 자세한 설명을 가져옵니다.

Source

오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
StackTrace

호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.

(다음에서 상속됨 Exception)
TargetSite

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetFilename(XmlNode)

이 구성 예외가 throw되었을 때 내부 XmlNode 개체를 로드한 구성 파일에 대한 경로를 가져옵니다.

GetFilename(XmlReader)

이 구성 예외가 throw되었을 때 내부 XmlReader가 읽고 있던 구성 파일에 대한 경로를 가져옵니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLineNumber(XmlNode)

이 구성 예외가 throw되었을 때 내부 XmlNode 개체가 나타낸 구성 파일의 줄 번호를 가져옵니다.

GetLineNumber(XmlReader)

이 구성 예외가 throw되었을 때 내부 XmlReader 개체가 처리하고 있던 구성 파일의 줄 번호를 가져옵니다.

GetObjectData(SerializationInfo, StreamingContext)
사용되지 않음.

이 구성 예외가 발생한 파일 이름과 줄 번호를 사용하여 SerializationInfo 개체를 설정합니다.

GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않음.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상