英語で読む

次の方法で共有


Assembly.Location プロパティ

定義

マニフェストを格納している読み込み済みファイルの完全パスまたは UNC 位置を取得します。

C#
public virtual string Location { get; }

プロパティ値

マニフェストを格納している読み込み済みファイルの場所。 を使用 Load(Byte[])する場合など、バイト配列からアセンブリが読み込まれる場合、返される値は空の文字列 ("") です。

実装

例外

現在のアセンブリは、AssemblyBuilder オブジェクトによって表される動的アセンブリです。

次の例では、マニフェストを含む読み込まれたファイルの場所を表示します。

C#
Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Display the physical location of the assembly containing the manifest.
Console.WriteLine("Location=" + SampleAssembly.Location);
// The example displays the following output:
//   Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll

注釈

.NET 5 以降のバージョンでは、バンドルアセンブリの場合、返される値は空の文字列です。

.NET Frameworkのみ: 読み込まれたファイルがシャドウ コピーされた場合、場所はシャドウ コピー後のファイルの場所になります。 ファイルがシャドウ コピーされる前の場所を取得するには、 プロパティを CodeBase 使用します。

適用対象

製品 バージョン
.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, 10
.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

こちらもご覧ください