Assembly.Location プロパティ

定義

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

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

プロパティ値

String

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

実装

例外

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

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

Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
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= {0}", SampleAssembly->Location );
// The example displays the following output:
//    Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
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
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32()
Dim Type1 As Type
' 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 使用します。

適用対象

こちらもご覧ください