Assembly.CodeBase プロパティ

定義

AssemblyName オブジェクトなど、最初に指定したアセンブリの場所を取得します。

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

プロパティ値

最初に指定したアセンブリの場所。

実装

例外

.NET Core と .NET 5 以降のみ: すべての場合。

次の例では、 CodeBase プロパティを使用します。

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 以降のバージョンでは、バンドルされたアセンブリの場合、このプロパティは例外をスローします。

適用対象