英語で読む

次の方法で共有


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 オブジェクトで、初めに指定されたアセンブリの場所を取得します。

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; }

プロパティ値

初めに指定されたとおりのアセンブリの場所。

実装

属性

例外

.NET Core および .NET 5 以降のみ:すべての場合。

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

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

注釈

読み込まれたマニフェストを含むファイルへの絶対パスを取得するには、代わりに プロパティを Assembly.Location 使用します。

バイト配列を受け取るメソッドの Load オーバーロードを使用して、アセンブリがバイト配列として読み込まれた場合、このプロパティは、読み込まれたアセンブリの場所ではなく、メソッドの呼び出し元の場所を返します。

.NET 5 以降のバージョンでは、バンドルアセンブリの場合、このプロパティは例外をスローします。

適用対象

製品 バージョン (廃止)
.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