EntryPointNotFoundException 클래스

정의

진입 메서드가 없어서 클래스를 로드하지 못했을 때 throw되는 예외입니다.

public ref class EntryPointNotFoundException : TypeLoadException
public class EntryPointNotFoundException : TypeLoadException
[System.Serializable]
public class EntryPointNotFoundException : TypeLoadException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class EntryPointNotFoundException : TypeLoadException
type EntryPointNotFoundException = class
    inherit TypeLoadException
[<System.Serializable>]
type EntryPointNotFoundException = class
    inherit TypeLoadException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type EntryPointNotFoundException = class
    inherit TypeLoadException
Public Class EntryPointNotFoundException
Inherits TypeLoadException
상속
EntryPointNotFoundException
특성

설명

EntryPointNotFoundException 공용 언어 런타임이 어셈블리의 진입점을 식별할 수 없으므로 어셈블리를 로드할 수 없는 경우 예외가 throw됩니다. 이 예외는 다음 조건에서 throw될 수 있습니다.

  • 공용 언어 런타임 애플리케이션 진입점을 찾을 수 없는 (일반적으로 Main 메서드)에서 실행 가능한 어셈블리. 애플리케이션 진입점이 전역 여야 합니다 또는 static 메서드 매개 변수 없이 또는 유일한 매개 변수로 문자열 배열입니다. 진입점은 를 반환void하거나 또는 UInt32 종료 코드를 반환할 Int32 수 있습니다. 애플리케이션 어셈블리는 둘 이상의 진입점을 정의할 수 없습니다.

  • 함수를 찾을 수 없으므로 Windows DLL에서 함수에 대한 호출을 확인할 수 없습니다. 다음 예제 EntryPointNotFoundException 에서는 User32.dll 라는 GetMyNumber함수를 포함하지 않으므로 예외가 throw됩니다.

    using System;
    using System.Runtime.InteropServices;
    
    public class Example
    {
       [DllImport("user32.dll")]
       public static extern int GetMyNumber();
    
       public static void Main()
       {
          try {
             int number = GetMyNumber();
          }
          catch (EntryPointNotFoundException e) {
             Console.WriteLine("{0}:\n   {1}", e.GetType().Name,
                               e.Message);
          }
       }
    }
    // The example displays the following output:
    //    EntryPointNotFoundException:
    //       Unable to find an entry point named 'GetMyNumber' in DLL 'User32.dll'.
    
    open System
    open System.Runtime.InteropServices
    
    [<DllImport "user32.dll">]
    extern int GetMyNumber()
    
    try
        let number = GetMyNumber()
        ()
    with :? EntryPointNotFoundException as e ->
        printfn $"{e.GetType().Name}:\n   {e.Message}"
    
    // The example displays the following output:
    //    EntryPointNotFoundException:
    //       Unable to find an entry point named 'GetMyNumber' in DLL 'User32.dll'.
    
    Module Example
        Declare Auto Function GetMyNumber Lib "User32.dll" () As Integer
    
       Public Sub Main()
          Try
             Dim number As Integer = GetMyNumber()
          Catch e As EntryPointNotFoundException
             Console.WriteLine("{0}:{2}   {1}", e.GetType().Name,  
                               e.Message, vbCrLf)
          End Try   
       End Sub
    End Module
    ' The example displays the following output:
    '    EntryPointNotFoundException:
    '       Unable to find an entry point named 'GetMyNumber' in DLL 'User32.dll'.
    
  • 메서드 호출에 사용된 이름이 어셈블리에 있는 이름과 일치하지 않으므로 Windows DLL의 함수 호출을 확인할 수 없습니다. 필드가 암시적으로 또는 명시적으로 로 설정true되고 호출된 메서드에 하나 이상의 문자열 매개 변수가 포함되어 있고 ANSI 및 유니코드 버전이 모두 있고 메서드 호출에 사용된 이름이 이 ANSI 또는 유니코드 버전의 이름과 일치하지 않기 때문에 DllImportAttribute.ExactSpelling 이 문제가 자주 발생합니다. 다음 예제에서는 User32.dll Windows MessageBox 함수를 호출하려고 시도하여 그림을 제공합니다. 첫 번째 메서드 정의는 문자열 마샬링에 대해 지정 CharSet.Unicode 하기 때문에 공용 언어는 메서드 호출에 사용되는 이름 대신 함수 MessageBoxW의 와이드 문자 버전 를 MessageBox찾습니다. 두 번째 메서드 정의는 함수 대신 를 MessageBoxW 호출하여 이 문제를 해결합니다 MessageBox .

    using System;
    using System.Runtime.InteropServices;
    
    public class Example
    {
       [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true )]
       public static extern int MessageBox(IntPtr hwnd, String text, String caption, uint type);
    
       [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true )]
       public static extern int MessageBoxW(IntPtr hwnd, String text, String caption, uint type);
    
       public static void Main()
       {
          try {
             MessageBox(new IntPtr(0), "Calling the MessageBox Function", "Example", 0);
          }
          catch (EntryPointNotFoundException e) {
             Console.WriteLine("{0}:\n   {1}", e.GetType().Name,
                               e.Message);
          }
    
          try {
             MessageBoxW(new IntPtr(0), "Calling the MessageBox Function", "Example", 0);
          }
          catch (EntryPointNotFoundException e) {
             Console.WriteLine("{0}:\n   {1}", e.GetType().Name,
                               e.Message);
          }
       }
    }
    
    open System
    open System.Runtime.InteropServices
    
    [<DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true )>]
    extern int MessageBox(IntPtr hwnd, String text, String caption, uint ``type``)
    
    [<DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true )>]
    extern int MessageBoxW(IntPtr hwnd, String text, String caption, uint ``type``)
    
    try
        MessageBox(IntPtr 0, "Calling the MessageBox Function", "Example", 0u)
        |> ignore
    with :? EntryPointNotFoundException as e ->
        printfn $"{e.GetType().Name}:\n   {e.Message}"
    
    try
        MessageBoxW(IntPtr 0, "Calling the MessageBox Function", "Example", 0u)
        |> ignore
    with :? EntryPointNotFoundException as e ->
        printfn $"{e.GetType().Name}:\n   {e.Message}"
    
    Module Example
       Declare Unicode Function MessageBox Lib "User32.dll" Alias "MessageBox" (
          ByVal hWnd As IntPtr, ByVal txt As String, ByVal caption As String, 
          ByVal typ As UInteger) As Integer  
    
       Declare Unicode Function MessageBox2 Lib "User32.dll" Alias "MessageBoxW" (  
          ByVal hWnd As IntPtr, ByVal txt As String, ByVal caption As String, 
          ByVal typ As UInteger) As Integer  
          
       Public Sub Main()
          Try
             MessageBox(IntPtr.Zero, "Calling the MessageBox Function", "Example", 0 )
          Catch e As EntryPointNotFoundException
             Console.WriteLine("{0}:{2}   {1}", e.GetType().Name,  
                               e.Message, vbCrLf)
          End Try
    
          Try
             MessageBox2(IntPtr.Zero, "Calling the MessageBox Function", "Example", 0 )
          Catch e As EntryPointNotFoundException
             Console.WriteLine("{0}:{2}   {1}", e.GetType().Name,  
                               e.Message, vbCrLf)
          End Try
    
       End Sub
    End Module
    
  • 동적 링크 라이브러리에서 함수를 데코레이트된 이름이 아닌 간단한 이름으로 호출하려고 합니다. 일반적으로 C++ 컴파일러는 DLL 함수에 대해 데코레이트된 이름을 생성합니다. 예를 들어 다음 C++ 코드는 TestDll.dll 라이브러리에 라는 Double 함수를 정의합니다.

    __declspec(dllexport) int Double(int number)
    {
        return number * 2;
    }
    

    다음 예제의 코드에서 함수를 호출하려고 하면 함수를 EntryPointNotFoundException 찾을 수 없으므로 예외가 Double throw됩니다.

    using System;
    using System.Runtime.InteropServices;
    
    public class Example
    {
       [DllImport("TestDll.dll")]
       public static extern int Double(int number);
    
       public static void Main()
       {
          Console.WriteLine(Double(10));
       }
    }
    // The example displays the following output:
    //    Unhandled Exception: System.EntryPointNotFoundException: Unable to find
    //    an entry point named 'Double' in DLL '.\TestDll.dll'.
    //       at Example.Double(Int32 number)
    //       at Example.Main()
    
    open System
    open System.Runtime.InteropServices
    
    [<DllImport "TestDll.dll">]
    extern int Double(int number)
    
    printfn $"{Double 10}"
    // The example displays the following output:
    //    Unhandled Exception: System.EntryPointNotFoundException: Unable to find
    //    an entry point named 'Double' in DLL '.\TestDll.dll'.
    //       at Example.Double(Int32 number)
    //       at Example.Main()
    
    Module Example
       Public Declare Function DoubleNum Lib ".\TestDll.dll" Alias "Double" _
                      (ByVal number As Integer) As Integer
       
       Public Sub Main()
          Console.WriteLine(DoubleNum(10))
       End Sub
    End Module
    ' The example displays the following output:
    '    Unhandled Exception: System.EntryPointNotFoundException: Unable to find an 
    '    entry point named 'Double' in DLL '.\TestDll.dll'.
    '       at Example.Double(Int32 number)
    '       at Example.Main()
    

    그러나 데코레이트된 이름(이 경우 ?Double@@YAHH@Z)을 사용하여 함수를 호출하면 다음 예제와 같이 함수 호출이 성공합니다.

    using System;
    using System.Runtime.InteropServices;
    
    public class Example
    {
       [DllImport("TestDll.dll", EntryPoint = "?Double@@YAHH@Z")]
       public static extern int Double(int number);
    
       public static void Main()
       {
          Console.WriteLine(Double(10));
       }
    }
    // The example displays the following output:
    //    20
    
    open System
    open System.Runtime.InteropServices
    
    [<DllImport("TestDll.dll", EntryPoint = "?Double@@YAHH@Z")>]
    extern int Double(int number)
    
    printfn $"{Double 10}"
    // The example displays the following output:
    //    20
    
    Module Example
       Public Declare Function DoubleNum Lib ".\TestDll.dll" Alias "?Double@@YAHH@Z" _
                      (ByVal number As Integer) As Integer
       
       Public Sub Main()
          Console.WriteLine(DoubleNum(10))
       End Sub
    End Module
    ' The example displays the following output:
    '    20
    

    Dumpbin.exe 같은 유틸리티를 사용하여 DLL에서 내보낸 함수의 데코레이트된 이름을 찾을 수 있습니다.

  • 관리되는 어셈블리에서 메서드를 관리되지 않는 동적 링크 라이브러리인 것처럼 호출하려고 합니다. 이 동작을 확인하려면 다음 예제를 StringUtilities.dll 라는 어셈블리로 컴파일합니다.

    using System;
    
    public static class StringUtilities
    {
       public static String SayGoodMorning(String name)
       {
          return String.Format("A top of the morning to you, {0}!", name);
       }
    }
    
    module StringUtilities
    
    let SayGoodMorning name =
        $"A top of the morning to you, %s{name}!"
    
    Module StringUtilities
       Public Function SayGoodMorning(name As String) As String
          Return String.Format("A top of the morning to you, {0}!", name)
       End Function
    End Module
    

    그런 다음 StringUtilities.dll 동적 링크 라이브러리에서 메서드를 비관리 코드처럼 호출 StringUtilities.SayGoodMorning 하려고 시도하는 다음 예제를 컴파일하고 실행합니다. 결과는 예외입니다 EntryPointNotFoundException .

    using System;
    using System.Runtime.InteropServices;
    
    public class Example
    {
       [DllImport("StringUtilities.dll", CharSet = CharSet.Unicode )]
       public static extern String SayGoodMorning(String name);
    
       public static void Main()
       {
          Console.WriteLine(SayGoodMorning("Dakota"));
       }
    }
    // The example displays the following output:
    //    Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point
    //    named 'GoodMorning' in DLL 'StringUtilities.dll'.
    //       at Example.GoodMorning(String& name)
    //       at Example.Main()
    
    open System
    open System.Runtime.InteropServices
    
    [<DllImport("StringUtilities.dll", CharSet = CharSet.Unicode )>]
    extern String SayGoodMorning(String name)
    
    printfn $"""{SayGoodMorning "Dakota"}"""
    // The example displays the following output:
    //    Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point
    //    named 'GoodMorning' in DLL 'StringUtilities.dll'.
    //       at Example.GoodMorning(String& name)
    //       at Example.Main()
    
    Module Example
       Declare Unicode Function GoodMorning Lib "StringUtilities.dll" (
          ByVal name As String) As String  
    
       Public Sub Main()
          Console.WriteLine(SayGoodMorning("Dakota"))
       End Sub
    End Module
    ' The example displays the following output:
    '    Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point 
    '    named 'GoodMorning' in DLL 'StringUtilities.dll'.
    '       at Example.GoodMorning(String& name)
    '       at Example.Main()
    

    예외를 제거하려면 다음 예제와 같이 관리되는 어셈블리에 대한 참조를 추가하고 관리 코드의 다른 메서드에 액세스하는 것처럼 메서드에 액세스 StringUtilities.SayGoodMorning 합니다.

    using System;
    
    public class Example
    {
       public static void Main()
       {
           Console.WriteLine(StringUtilities.SayGoodMorning("Dakota"));
       }
    }
    // The example displays the following output:
    //        A top of the morning to you, Dakota!
    
    printfn $"""{StringUtilities.SayGoodMorning "Dakota"}"""
    // The example displays the following output:
    //        A top of the morning to you, Dakota!
    
    Module Example
       Public Sub Main()
          Console.WriteLine(StringUtilities.SayGoodMorning("Dakota"))
       End Sub
    End Module
    ' The example displays the following output:
    '       A top of the morning to you, Dakota!
    
  • COM DLL에서 메서드를 Windows DLL인 것처럼 호출하려고 합니다. COM DLL에 액세스하려면 Visual Studio에서 참조 추가 옵션을 선택하여 프로젝트에 대한 참조를 추가한 다음 COM 탭에서 형식 라이브러리를 선택합니다.

인스턴스의 초기 속성 값의 목록을 EntryPointNotFoundException, 참조는 EntryPointNotFoundException 생성자입니다.

생성자

EntryPointNotFoundException()

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

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

serialize된 데이터를 사용하여 EntryPointNotFoundException 클래스의 새 인스턴스를 초기화합니다.

EntryPointNotFoundException(String)

지정된 오류 메시지를 사용하여 EntryPointNotFoundException 클래스의 새 인스턴스를 초기화합니다.

EntryPointNotFoundException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 EntryPointNotFoundException 클래스의 새 인스턴스를 초기화합니다.

속성

Data

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

(다음에서 상속됨 Exception)
HelpLink

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

(다음에서 상속됨 Exception)
HResult

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

(다음에서 상속됨 Exception)
InnerException

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

(다음에서 상속됨 Exception)
Message

이 예외에 대한 오류 메시지를 가져옵니다.

(다음에서 상속됨 TypeLoadException)
Source

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

(다음에서 상속됨 Exception)
StackTrace

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

(다음에서 상속됨 Exception)
TargetSite

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

(다음에서 상속됨 Exception)
TypeName

이 예외를 발생시킨 형식의 정규화된 이름을 가져옵니다.

(다음에서 상속됨 TypeLoadException)

메서드

Equals(Object)

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

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

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

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

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

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)
사용되지 않음.

클래스 이름, 메서드 이름, 리소스 ID 및 추가 예외 정보를 사용하여 SerializationInfo 개체를 설정합니다.

(다음에서 상속됨 TypeLoadException)
GetType()

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

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

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

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

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

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않음.

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

(다음에서 상속됨 Exception)

적용 대상

추가 정보