Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Clase EntryPointNotFoundException

 

Publicado: octubre de 2016

Excepción que se produce cuando se produce un error al intentar cargar una clase debido a la ausencia de un método de entrada.

Espacio de nombres:   System
Ensamblado:  mscorlib (en mscorlib.dll)

System.Object
  System.Exception
    System.SystemException
      System.TypeLoadException
        System.EntryPointNotFoundException

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class EntryPointNotFoundException : TypeLoadException

NombreDescripción
System_CAPS_pubmethodEntryPointNotFoundException()

Inicializa una nueva instancia de la clase EntryPointNotFoundException.

System_CAPS_protmethodEntryPointNotFoundException(SerializationInfo, StreamingContext)

Inicializa una nueva instancia de la clase EntryPointNotFoundException con datos serializados.

System_CAPS_pubmethodEntryPointNotFoundException(String)

Inicializa una nueva instancia de la clase EntryPointNotFoundException con el mensaje de error especificado.

System_CAPS_pubmethodEntryPointNotFoundException(String, Exception)

Inicializa una nueva instancia de la clase EntryPointNotFoundException con el mensaje de error especificado y una referencia a la excepción interna que representa la causa de esta excepción.

NombreDescripción
System_CAPS_pubpropertyData

Obtiene una colección de pares clave-valor que proporcionan más información definida por el usuario sobre la excepción.(Heredado de Exception).

System_CAPS_pubpropertyHelpLink

Obtiene o establece un vínculo al archivo de ayuda asociado a esta excepción.(Heredado de Exception).

System_CAPS_pubpropertyHResult

Obtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica.(Heredado de Exception).

System_CAPS_pubpropertyInnerException

Obtiene la instancia Exception que produjo la excepción actual.(Heredado de Exception).

System_CAPS_pubpropertyMessage

Obtiene el mensaje de error para esta excepción.(Heredado de TypeLoadException).

System_CAPS_pubpropertySource

Devuelve o establece el nombre de la aplicación o del objeto que generó el error.(Heredado de Exception).

System_CAPS_pubpropertyStackTrace

Obtiene una representación de cadena de los marcos inmediatos en la pila de llamadas.(Heredado de Exception).

System_CAPS_pubpropertyTargetSite

Obtiene el método que produjo la excepción actual.(Heredado de Exception).

System_CAPS_pubpropertyTypeName

Obtiene el nombre completo del tipo que genera la excepción.(Heredado de TypeLoadException).

NombreDescripción
System_CAPS_pubmethodEquals(Object)

Determina si el objeto especificado es igual al objeto actual.(Heredado de Object).

System_CAPS_protmethodFinalize()

Permite que un objeto intente liberar recursos y realizar otras operaciones de limpieza antes de ser reclamado por el recolector de basura. (Heredado de Object).

System_CAPS_pubmethodGetBaseException()

Cuando se invalida en una clase derivada, devuelve la clase Exception que representa la causa principal de una o más excepciones posteriores.(Heredado de Exception).

System_CAPS_pubmethodGetHashCode()

Sirve como la función hash predeterminada.(Heredado de Object).

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

Establece el objeto SerializationInfo con el nombre de la clase, el nombre del método, el id. de recurso y la información adicional de la excepción.(Heredado de TypeLoadException).

System_CAPS_pubmethodGetType()

Obtiene el tipo en tiempo de ejecución de la instancia actual.(Heredado de Exception).

System_CAPS_protmethodMemberwiseClone()

Crea una copia superficial del Object actual.(Heredado de Object).

System_CAPS_pubmethodToString()

Crea y devuelve una representación de cadena de la excepción actual.(Heredado de Exception).

NombreDescripción
System_CAPS_proteventSerializeObjectState

Ocurre cuando una excepción se serializa para crear un objeto de estado de excepción que contenga datos serializados sobre la excepción.(Heredado de Exception).

An T:System.EntryPointNotFoundException exception is thrown when the common language runtime is unable to load an assembly because it cannot identify the assembly's entry point. This exception can be thrown under the following conditions:

  • The common language runtime is unable to locate an application entry point (typically a Main method) in an executable assembly. The application entry point must be a global or static method that has either no parameters or a string array as its only parameter. The entry point can return void, or it can return an T:System.Int32 or T:System.UInt32 exit code. An application assembly cannot define more than one entry point.

  • The call to a function in a Windows DLL cannot be resolved because the function cannot be found. In the following example, an T:System.EntryPointNotFoundException exception is thrown because User32.dll does not include a function named 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'.
    
  • The call to a function in a Windows DLL cannot be resolved because the name used in the method call does not match a name found in the assembly. Frequently, this occurs because the F:System.Runtime.InteropServices.DllImportAttribute.ExactSpelling field is either implicitly or explicitly set to true, the called method includes one or more string parameters and has both an ANSI and a Unicode version, and the name used in the method call does not correspond to the name of this ANSI or Unicode version. The following example provides an illustration by attempting to call the Windows MessageBox function in User32.dll. Because the first method definition specifies F:System.Runtime.InteropServices.CharSet.Unicode for string marshaling, the common language looks for the wide-character version of the function, MessageBoxW, instead of the name used in the method call, MessageBox. The second method definition corrects this problem by calling the MessageBoxW instead of the MessageBox function.

    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);
          }
       }
    }
    
  • You are trying to call a function in a dynamic link library by its simple name rather than its decorated name. Typically, the C++ compiler generates a decorated name for DLL functions. For example, the following C++ code defines a function named Double in a library named TestDll.dll.

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

    When the code in the following example tries to call the function, an T:System.EntryPointNotFoundException exception is thrown because the Double function cannot be found.

    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()
    

    However, if the function is called by using its decorated name (in this case, ?Double@@YAHH@Z), the function call succeeds, as the following example shows.

    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
    

    You can find the decorated names of functions exported by a DLL by using a utility such as Dumpbin.exe.

  • You are attempting to call a method in a managed assembly as if it were an unmanaged dynamic link library. To see this in action, compile the following example to an assembly named 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);
       }
    }
    

    Then compile and execute the following example, which attempts to call the StringUtilities.SayGoodMorning method in the StringUtilities.dll dynamic link library as if it were unmanaged code. The result is an T:System.EntryPointNotFoundException exception.

    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()
    

    To eliminate the exception, add a reference to the managed assembly and access the StringUtilities.SayGoodMorning method just as you would access any other method in managed code, as the following example does.

    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!
    
  • You are trying to call a method in a COM DLL as if it were a Windows DLL. To access a COM DLL, select the Add Reference option in Visual Studio to add a reference to the project, and then select the type library from the COM tab.

For a list of initial property values for an instance of T:System.EntryPointNotFoundException, see the M:System.EntryPointNotFoundException.#ctor constructors.

.NET Framework
Disponible desde 1.1
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Volver al principio
Mostrar: