Leer en inglés

Compartir a través de


Assembly.CodeBase Propiedad

Definición

Precaución

Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location instead.

Precaución

Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.

Obtiene la ubicación del ensamblado tal como se especificó originalmente, por ejemplo, en un objeto AssemblyName.

C#
[System.Obsolete("Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location instead.", DiagnosticId="SYSLIB0012", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual string? CodeBase { get; }
C#
[System.Obsolete("Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.", DiagnosticId="SYSLIB0012", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual string? CodeBase { get; }
C#
public virtual string CodeBase { get; }
C#
public virtual string? CodeBase { get; }

Valor de propiedad

Ubicación del ensamblado tal y como se especificó originalmente.

Implementaciones

Atributos

Excepciones

.NET Core y .NET 5+ solo: En todos los casos.

Ejemplos

En el ejemplo siguiente se usa la CodeBase propiedad .

C#
using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      // Instantiate a target object.
      Int32 integer1 = 1632;
      // Instantiate an Assembly class to the assembly housing the Integer type.
      Assembly systemAssembly = integer1.GetType().Assembly;
      // Get the location of the assembly using the file: protocol.
      Console.WriteLine("CodeBase = {0}", systemAssembly.CodeBase);
   }
}
// The example displays output like the following:
//    CodeBase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll

Comentarios

Para obtener la ruta de acceso absoluta al archivo contenedor de manifiesto cargado, use la Assembly.Location propiedad en su lugar.

Si el ensamblado se cargó como una matriz de bytes, utilizando una sobrecarga del Load método que toma una matriz de bytes, esta propiedad devuelve la ubicación del autor de la llamada del método, no la ubicación del ensamblado cargado.

En .NET 5 y versiones posteriores, para ensamblados agrupados, esta propiedad produce una excepción.

Se aplica a

Producto Versiones (Obsoleto)
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1 (5, 6, 7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1