Assembly.CodeBase Properti

Definisi

Mendapatkan lokasi rakitan seperti yang ditentukan awalnya, misalnya, dalam AssemblyName objek.

public:
 virtual property System::String ^ CodeBase { System::String ^ get(); };
public virtual string CodeBase { get; }
member this.CodeBase : string
Public Overridable ReadOnly Property CodeBase As String

Nilai Properti

Lokasi rakitan seperti yang ditentukan awalnya.

Penerapan

Pengecualian

.NET Core dan .NET 5+ saja: Dalam semua kasus.

Contoh

Contoh berikut menggunakan CodeBase properti .

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
Imports System.Reflection

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

Keterangan

Untuk mendapatkan jalur absolut ke file yang berisi manifes yang dimuat, gunakan properti sebagai gantinya Assembly.Location .

Jika rakitan dimuat sebagai array byte, menggunakan kelebihan beban Load metode yang mengambil array byte, properti ini mengembalikan lokasi pemanggil metode, bukan lokasi rakitan yang dimuat.

Di .NET 5 dan versi yang lebih baru, untuk rakitan yang dibundel, properti ini melemparkan pengecualian.

Berlaku untuk