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

Assembly.GetExecutingAssembly (Método) ()

 

Obtiene el ensamblado que contiene el código que se está ejecutando actualmente.

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

public static Assembly GetExecutingAssembly()

Valor devuelto

Type: System.Reflection.Assembly

Ensamblado que contiene el código que se está ejecutando actualmente.

For performance reasons, you should call this method only when you do not know at design time what assembly is currently executing. The recommended way to retrieve an T:System.Reflection.Assembly object that represents the current assembly is to use the P:System.Type.Assembly property of a type found in the assembly, as the following example illustrates.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      Assembly assem = typeof(Example).Assembly;
      Console.WriteLine("Assembly name: {0}", assem.FullName);
   }
}
// The example displays output like the following:
//    Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

To get the assembly that contains the method that called the currently executing code, use M:System.Reflection.Assembly.GetCallingAssembly.

The following example uses the P:System.Type.Assembly property to get the currently executing assembly based on a type contained in that assembly. It also calls the M:System.Reflection.Assembly.GetExecutingAssembly method to show that it returns an T:System.Reflection.Assembly object that represents the same assembly.

using System;
using System.Reflection;

class Example
{
   static void Main()
   {
      // Get the assembly from a known type in that assembly.
      Type t = typeof(Example);
      Assembly assemFromType = t.Assembly;
      Console.WriteLine("Assembly that contains Example:");
      Console.WriteLine("   {0}\n", assemFromType.FullName);

      // Get the currently executing assembly.
      Assembly currentAssem = Assembly.GetExecutingAssembly();
      Console.WriteLine("Currently executing assembly:");
      Console.WriteLine("   {0}\n", currentAssem.FullName);

      Console.WriteLine("The two Assembly objects are equal: {0}",
                        assemFromType.Equals(currentAssem));
   }
}
// The example displays the following output:
//    Assembly that contains Example:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    Currently executing assembly:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    The two Assembly objects are equal: True

.NET Framework
Disponible desde 1.1
Portable Class Library
Compatible con: portable .NET platforms
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Volver al principio
Mostrar: