EntryPointNotFoundException Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Pengecualian yang dilemparkan ketika upaya untuk memuat kelas gagal karena tidak adanya metode entri.
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
- Warisan
- Atribut
Keterangan
Pengecualian EntryPointNotFoundException dilemparkan ketika runtime bahasa umum tidak dapat memuat assembly karena tidak dapat mengidentifikasi titik masuk assembly. Pengecualian ini dapat dilemparkan dalam kondisi berikut:
Runtime bahasa umum tidak dapat menemukan titik entri aplikasi (biasanya
Mainmetode) dalam rakitan yang dapat dieksekusi. Titik entri aplikasi harus berupa global ataustaticmetode yang tidak memiliki parameter atau array string sebagai satu-satunya parameternya. Titik entri dapat mengembalikanvoid, atau dapat mengembalikan Int32 kode keluar atau UInt32 . Rakitan aplikasi tidak dapat menentukan lebih dari satu titik masuk.Panggilan ke fungsi dalam DLL Windows tidak dapat diselesaikan karena fungsi tidak dapat ditemukan. Dalam contoh berikut, EntryPointNotFoundException pengecualian dilemparkan karena User32.dll tidak menyertakan fungsi bernama
GetMyNumber.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'.Panggilan ke fungsi dalam DLL Windows tidak dapat diselesaikan karena nama yang digunakan dalam panggilan metode tidak cocok dengan nama yang ditemukan di rakitan. Sering kali, ini terjadi karena DllImportAttribute.ExactSpelling bidang diatur secara implisit atau eksplisit ke
true, metode yang dipanggil mencakup satu atau beberapa parameter string dan memiliki versi ANSI dan Unicode, dan nama yang digunakan dalam panggilan metode tidak sesuai dengan nama versi ANSI atau Unicode ini. Contoh berikut memberikan ilustrasi dengan mencoba memanggil fungsi WindowsMessageBoxdi User32.dll. Karena definisi metode pertama menentukan CharSet.Unicode untuk marshaling string, bahasa umum mencari versi karakter luas fungsi,MessageBoxW, alih-alih nama yang digunakan dalam panggilan metode,MessageBox. Definisi metode kedua memperbaiki masalah ini dengan memanggilMessageBoxWalih-alihMessageBoxfungsi .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 ModuleAnda mencoba memanggil fungsi di pustaka tautan dinamis dengan nama sederhananya daripada nama yang dihiasi. Biasanya, pengkompilasi C++ menghasilkan nama yang didekorasi untuk fungsi DLL. Misalnya, kode C++ berikut menentukan fungsi bernama
Doubledalam pustaka bernama TestDll.dll.__declspec(dllexport) int Double(int number) { return number * 2; }Ketika kode dalam contoh berikut mencoba memanggil fungsi, EntryPointNotFoundException pengecualian dilemparkan karena
Doublefungsi tidak dapat ditemukan.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()Namun, jika fungsi dipanggil dengan menggunakan nama yang didekorasi (dalam hal ini,
?Double@@YAHH@Z), panggilan fungsi berhasil, seperti yang ditunjukkan contoh berikut.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: // 20open 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: // 20Module 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: ' 20Anda dapat menemukan nama fungsi yang didekorasi yang diekspor oleh DLL dengan menggunakan utilitas seperti Dumpbin.exe.
Anda mencoba memanggil metode dalam rakitan terkelola seolah-olah itu adalah pustaka tautan dinamis yang tidak terkelola. Untuk melihat tindakan ini, kompilasi contoh berikut ke rakitan bernama 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 ModuleKemudian kompilasi dan jalankan contoh berikut, yang mencoba memanggil
StringUtilities.SayGoodMorningmetode di pustaka tautan dinamis StringUtilities.dll seolah-olah itu adalah kode yang tidak dikelola. Hasilnya adalah EntryPointNotFoundException pengecualian.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()Untuk menghilangkan pengecualian, tambahkan referensi ke rakitan terkelola dan akses
StringUtilities.SayGoodMorningmetode sama seperti Anda akan mengakses metode lain dalam kode terkelola, seperti contoh berikut.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!Anda mencoba memanggil metode dalam DLL COM seolah-olah itu adalah DLL Windows. Untuk mengakses DLL COM, pilih opsi Tambahkan Referensi di Visual Studio untuk menambahkan referensi ke proyek, lalu pilih pustaka jenis dari tab COM .
Untuk daftar nilai properti awal untuk instans EntryPointNotFoundException, lihat EntryPointNotFoundException konstruktor.
Konstruktor
| EntryPointNotFoundException() |
Menginisialisasi instans baru kelas EntryPointNotFoundException. |
| EntryPointNotFoundException(SerializationInfo, StreamingContext) |
Kedaluwarsa.
Menginisialisasi instans EntryPointNotFoundException baru kelas dengan data berseri. |
| EntryPointNotFoundException(String) |
Menginisialisasi instans EntryPointNotFoundException baru kelas dengan pesan kesalahan yang ditentukan. |
| EntryPointNotFoundException(String, Exception) |
Menginisialisasi instans EntryPointNotFoundException baru kelas dengan pesan kesalahan yang ditentukan dan referensi ke pengecualian dalam yang merupakan penyebab pengecualian ini. |
Properti
| Data |
Mendapatkan kumpulan pasangan kunci/nilai yang memberikan informasi tambahan yang ditentukan pengguna tentang pengecualian. (Diperoleh dari Exception) |
| HelpLink |
Mendapatkan atau mengatur tautan ke file bantuan yang terkait dengan pengecualian ini. (Diperoleh dari Exception) |
| HResult |
Mendapatkan atau menetapkan HRESULT, nilai numerik berkode yang ditetapkan ke pengecualian tertentu. (Diperoleh dari Exception) |
| InnerException |
Mendapatkan instans Exception yang menyebabkan pengecualian saat ini. (Diperoleh dari Exception) |
| Message |
Mendapatkan pesan kesalahan untuk pengecualian ini. (Diperoleh dari TypeLoadException) |
| Source |
Get dan set nama aplikasi atau objek yang menyebabkan kesalahan. (Diperoleh dari Exception) |
| StackTrace |
Mendapatkan representasi string dari bingkai langsung pada tumpukan panggilan. (Diperoleh dari Exception) |
| TargetSite |
Mendapatkan metode yang melemparkan pengecualian saat ini. (Diperoleh dari Exception) |
| TypeName |
Mendapatkan nama yang sepenuhnya memenuhi syarat dari jenis yang menyebabkan pengecualian. (Diperoleh dari TypeLoadException) |
Metode
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetBaseException() |
Ketika ditimpa di kelas turunan, mengembalikan Exception yang merupakan akar penyebab dari satu atau beberapa pengecualian berikutnya. (Diperoleh dari Exception) |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Kedaluwarsa.
SerializationInfo Mengatur objek dengan nama kelas, nama metode, ID sumber daya, dan informasi pengecualian tambahan. (Diperoleh dari TypeLoadException) |
| GetType() |
Mendapatkan jenis runtime instans saat ini. (Diperoleh dari Exception) |
| MemberwiseClone() |
Membuat salinan dangkal dari yang saat ini Object. (Diperoleh dari Object) |
| ToString() |
Membuat dan mengembalikan representasi string dari pengecualian saat ini. (Diperoleh dari Exception) |
Acara
| SerializeObjectState |
Kedaluwarsa.
Terjadi ketika pengecualian diserialisasikan untuk membuat objek status pengecualian yang berisi data berseri tentang pengecualian. (Diperoleh dari Exception) |