System.Reflection.Metadata 10.0.0-rc.2.25502.107
About
This package provides a low-level .NET (ECMA-335) metadata reader and writer. It's geared for performance and is the ideal choice for building higher-level libraries that intend to provide their own object model, such as compilers. The metadata format is defined by the ECMA-335 - Common Language Infrastructure (CLI) specification and its amendments.
The System.Reflection.Metadata library is included in the .NET Runtime shared framework. The package can be installed when you need to use it in other target frameworks.
How to Use
The following example shows how to read assembly information using PEReader and MetadataReader.
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
class Program
{
static void Main()
{
// Open the Portable Executable (PE) file
using var fs = new FileStream("Example.dll", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var peReader = new PEReader(fs);
// Display PE header information
PEHeader header = peReader.PEHeaders.PEHeader;
Console.WriteLine($"Image base: 0x{header.ImageBase:X}");
Console.WriteLine($"File alignment: 0x{header.FileAlignment:X}");
Console.WriteLine($"Subsystem: {header.Subsystem}");
// Display .NET metadata information
if (!peReader.HasMetadata)
{
Console.WriteLine("Image does not contain .NET metadata");
return;
}
MetadataReader mr = peReader.GetMetadataReader();
AssemblyDefinition ad = mr.GetAssemblyDefinition();
Console.WriteLine($"Assembly name: {ad.GetAssemblyName().ToString()}");
Console.WriteLine();
Console.WriteLine("Assembly attributes:");
foreach (CustomAttributeHandle attrHandle in ad.GetCustomAttributes())
{
CustomAttribute attr = mr.GetCustomAttribute(attrHandle);
// Display the attribute type full name
if (attr.Constructor.Kind == HandleKind.MethodDefinition)
{
MethodDefinition mdef = mr.GetMethodDefinition((MethodDefinitionHandle)attr.Constructor);
TypeDefinition tdef = mr.GetTypeDefinition(mdef.GetDeclaringType());
Console.WriteLine($"{mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
}
else if (attr.Constructor.Kind == HandleKind.MemberReference)
{
MemberReference mref = mr.GetMemberReference((MemberReferenceHandle)attr.Constructor);
if (mref.Parent.Kind == HandleKind.TypeReference)
{
TypeReference tref = mr.GetTypeReference((TypeReferenceHandle)mref.Parent);
Console.WriteLine($"{mr.GetString(tref.Namespace)}.{mr.GetString(tref.Name)}");
}
else if (mref.Parent.Kind == HandleKind.TypeDefinition)
{
TypeDefinition tdef = mr.GetTypeDefinition((TypeDefinitionHandle)mref.Parent);
Console.WriteLine($"{mr.GetString(tdef.Namespace)}.{mr.GetString(tdef.Name)}");
}
}
}
}
}
Main Types
The main types provided by this library are:
System.Reflection.Metadata.MetadataReaderSystem.Reflection.PortableExecutable.PEReaderSystem.Reflection.Metadata.Ecma335.MetadataBuilderSystem.Reflection.PortableExecutable.PEBuilderSystem.Reflection.PortableExecutable.ManagedPEBuilder
Additional Documentation
- System.Reflection.Metadata.MetadataReader
- System.Reflection.PortableExecutable.PEReader
- System.Reflection.Metadata.Ecma335.MetadataBuilder
- System.Reflection.PortableExecutable.PEBuilder
- System.Reflection.PortableExecutable.ManagedPEBuilder
Feedback & Contributing
System.Reflection.Metadata is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on System.Reflection.Metadata.
| Packages | Downloads |
|---|---|
|
Microsoft.CodeAnalysis.Workspaces.MSBuild
.NET Compiler Platform ("Roslyn") support for analyzing MSBuild projects and solutions. This should be used with at least one
of the following packages to add the appropriate language support:
- Microsoft.CodeAnalysis.CSharp.Workspaces
- Microsoft.CodeAnalysis.VisualBasic.Workspaces
More details at https://aka.ms/roslyn-packages
This package was built from the source at https://github.com/dotnet/roslyn/commit/fa72fa61b0d822ea8a3fbeb96f668340419ab5cd.
|
18 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
5f979c18c12f4903b171ca8cefccceeb03b22c32
When using NuGet 3.x this package requires at least version 3.4.
|
17 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
When using NuGet 3.x this package requires at least version 3.4.
|
14 |
|
Microsoft.CodeAnalysis.CSharp
.NET Compiler Platform ("Roslyn") support for C#, Microsoft.CodeAnalysis.CSharp.dll.
More details at https://aka.ms/roslyn-packages
This package was built from the source at https://github.com/dotnet/roslyn/commit/cf82d399c36008e7936d545cde24141f8d3790fa.
|
14 |
|
Microsoft.CodeAnalysis.CSharp.Workspaces
.NET Compiler Platform ("Roslyn") support for analyzing C# projects and solutions.
More details at https://aka.ms/roslyn-packages
This package was built from the source at https://github.com/dotnet/roslyn/commit/dfa7fc6bdea31a858a402168384192b633c811fa.
|
13 |
|
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
|
12 |
|
Microsoft.AspNetCore.Hosting
ASP.NET Core hosting infrastructure and startup logic for web applications.
|
12 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
When using NuGet 3.x this package requires at least version 3.4.
|
12 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
290303f510986f8f832fd2dc9e313cebe06ec68d
When using NuGet 3.x this package requires at least version 3.4.
|
12 |
|
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
|
11 |
|
Microsoft.Diagnostics.Tracing.TraceEvent
Event Tracing for Windows (ETW) is a powerful logging mechanism built into the Windows OS and is used extensively in Windows.
You can also log ETW events yourself code using the System.Diagnostics.Tracing.EventSource class.
The TraceEvent library conains the classes needed to control ETW providers (including .NET EventSources)
and parse the events they emit.
The library includes
-- TraceEventSession which can enable ETW providers,
-- EtwTraceEventSource which lets you read the stream of ETW events, and
-- TraceLog which is is digested form of ETW events which include decoded stack traces associated with the events.
See https://github.com/Microsoft/perfview/blob/master/documentation/TraceEvent/TraceEventLibrary.md for more.
|
11 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
23677d3ee7d5160e2d6d420548cf58d74262df10
When using NuGet 3.x this package requires at least version 3.4.
|
11 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
caa7b7e2bad98e56a687fb5cbaf60825500800f7
When using NuGet 3.x this package requires at least version 3.4.
|
11 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
85255dde3ecd86987236868a0415acd3265258d2
When using NuGet 3.x this package requires at least version 3.4.
|
11 |
|
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model.
7b9e4ef7c114f04a1baf0143fad29c984364a5f5
When using NuGet 3.x this package requires at least version 3.4.
|
11 |
|
System.Formats.Nrbf
Provides a safe reader for .NET Remoting Binary Format (NRBF) payloads.
|
11 |
|
Microsoft.Build.Runtime
This package delivers a complete executable copy of MSBuild. Reference this package only if your application needs to load projects or execute in-process builds without requiring installation of MSBuild. Successfully evaluating projects using this package requires aggregating additional components (like the compilers) into an application directory.
|
11 |
|
bunit.xunit
bUnit.xunit is an xUnit extension for bUnit, that provides a way for xUnit to run bUnit's razor-based tests, as well as other helpful extensions to make the testing experience better if you use xUnit for writing your tests.
|
10 |
|
Microsoft.CodeAnalysis.Workspaces.Common
A shared package used by the .NET Compiler Platform ("Roslyn") including support for analyzing projects and solutions.
Do not install this package manually, it will be added as a prerequisite by other packages that require it.
More details at https://aka.ms/roslyn-packages
This package was built from the source at https://github.com/dotnet/roslyn/commit/8edf7bcd4f1594c3d68a6a567469f41dbd33dd1b.
|
10 |
|
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
|
10 |
.NET Framework 4.6.2
- System.Collections.Immutable (>= 10.0.0-rc.2.25502.107)
.NET 8.0
- System.Collections.Immutable (>= 10.0.0-rc.2.25502.107)
.NET 9.0
- System.Collections.Immutable (>= 10.0.0-rc.2.25502.107)
.NET 10.0
- No dependencies.
.NET Standard 2.0
- System.Collections.Immutable (>= 10.0.0-rc.2.25502.107)