Assembly.CodeBase プロパティ

定義

注意事項

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

たとえば AssemblyName オブジェクトで、初めに指定されたアセンブリの場所を取得します。Gets the location of the assembly as specified originally, for example, in an AssemblyName object.

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; }
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
member this.CodeBase : string
Public Overridable ReadOnly Property CodeBase As String

プロパティ値

String

初めに指定されたとおりのアセンブリの場所。The location of the assembly as specified originally.

実装

属性

次の例では、プロパティを使用し CodeBase ます。The following example uses the CodeBase property.

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 代わりにプロパティを使用します。To get the absolute path to the loaded manifest-containing file, use the Assembly.Location property instead.

バイト配列としてアセンブリが読み込まれた場合、バイト配列を受け取るメソッドのオーバーロードを使用して、このプロパティは、読み込まれた Load アセンブリの場所ではなく、メソッドの呼び出し元の場所を返します。If the assembly was loaded as a byte array, using an overload of the Load method that takes an array of bytes, this property returns the location of the caller of the method, not the location of the loaded assembly.

.NET 5.0 以降のバージョンでは、バンドルされたアセンブリの場合、このプロパティは例外をスローします。In .NET 5.0 and later versions, for bundled assemblies, this property throws an exception.

適用対象