Assembly.CodeBase 屬性

定義

警告

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

警告

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

取得組件位置,例如原先在 AssemblyName 物件中指定的。

public:
 virtual property System::String ^ CodeBase { System::String ^ get(); };
[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; }
[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; }
public virtual string CodeBase { get; }
public virtual string? CodeBase { get; }
[<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}")>]
member this.CodeBase : string
[<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}")>]
member this.CodeBase : string
member this.CodeBase : string
Public Overridable ReadOnly Property CodeBase As String

屬性值

原先指定的組件位置。

實作

屬性

例外狀況

僅限 .NET Core 與 .NET 5+:在所有情況下。

範例

下列範例會使用 CodeBase 屬性。

using namespace System;
using namespace System::Reflection;

void main()
{
   // Instantiate a target object.
   int 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
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

備註

若要取得載入之指令清單包含檔案的絕對路徑,請改用 Assembly.Location 屬性。

如果元件已載入為位元組數位,使用採用位元組數位列之方法的多載 Load ,這個屬性會傳回方法呼叫端的位置,而不是載入元件的位置。

在 .NET 5 和更新版本中,針對配套元件,此屬性會擲回例外狀況。

適用於