Overview of .NET Metadata Dumper
masterMicrosoft.Bcl.Metadata (Metadata Reader) library to inspect and extract metadata information.repository·master·Indexed 20 days ago
https://github.com/microsoft/dotnet-samplesA collection of specialized .NET samples demonstrating advanced usage of core libraries and diagnostic tools. Includes demonstrations for System.Numerics (SIMD), System.Reflection.Metadata (MD Dumper), Microsoft.Diagnostics.Runtime (CLR MD), and Microsoft.Diagnostics.Tracing (EventSource and TraceEvent). Additionally provides samples for handling High DPI (Per-Monitor and System Aware) in Windows Forms applications.
Microsoft.Bcl.Metadata (Metadata Reader) library to inspect and extract metadata information.The repository contains two primary types of HDPI implementation samples:
Microsoft.Diagnostics.Runtime, specifically the CLR MD sample. Use this to learn how to inspect the state of a managed runtime (CLR) during debugging or post-mortem analysis.System.Numerics, specifically focusing on SIMD (Single Instruction, Multiple Data) operations. Use these samples to understand how to leverage hardware acceleration for numerical computations in .NET.Microsoft.Diagnostics.Tracing, covering both EventSource and TraceEvent. These samples demonstrate how to implement event tracing and consume trace events for diagnostic purposes.The TraceEvent library provides extensive capabilities for ETW monitoring and analysis, including:
IObservable for Reactive Extensions) or scan .etl files..etl files or read/write/filter ETL files (Windows 8+).ETLX format for efficient random access and backward/forward enumeration.TraceParserGen to generate strongly typed C# parsers from any ETW manifest.This repository provides samples for handling High DPI in Windows Forms, specifically demonstrating:
Use these to ensure Windows Forms applications scale correctly across different monitor DPI settings.
System.Reflection.Metadata, including an MD Dumper sample. This is useful for developers needing to inspect and dump metadata from .NET assemblies.EventSource is a central class used by managed-code developers to create strongly typed specifications for logging events that can be captured by Event Tracing for Windows (ETW).
Instead of passing verbosity levels or event IDs at every call site, you define a class that encapsulates the event structure. This results in a 'minimal' call site where you only provide the logging object, the method representing the event, and the necessary strongly typed parameters.
Key Benefits:
int, string, or DateTime) are preserved through the event pipeline, eliminating the need for string parsing in viewers.// Example of a minimal call site
MinimalEventSource.Log.Load(0x40000, "MyFile0");While EventSource classes should generally be sealed, you can use an abstract base class to provide common, optimized WriteEvent overloads to multiple derived EventSource types.
Constraints for Abstract Base Classes:
Keywords, Tasks, Opcodes, Channels, or Events.WriteEvent wrappers) to be used by derived classes.public abstract class UtilBaseEventSource : EventSource
{
protected UtilBaseEventSource() : base() { }
protected UtilBaseEventSource(bool throwOnEventWriteErrors) : base(throwOnEventWriteErrors) { }
protected unsafe void WriteEvent(int eventId, int arg1, short arg2, long arg3)
{
if (IsEnabled())
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
descrs[0].DataPointer = (IntPtr)(&arg1);
descrs[0].Size = 4;
descrs[1].DataPointer = (IntPtr)(&arg2);
descrs[1].Size = 2;
descrs[2].DataPointer = (IntPtr)(&arg3);
descrs[2].Size = 8;
WriteEventCore(eventId, 3, descrs);
}
}
}
[EventSource(Name = "OptimizedEventSource")]
public sealed class OptimizedEventSource : UtilBaseEventSource
{
public static OptimizedEventSource Log = new OptimizedEventSource();
[Event(1, Keywords = Keywords.Kwd1, Level = EventLevel.Informational,
Message = "LogElements called {0}/{1}/{2}.")]
public void LogElements(int n, short sh, long l)
{
WriteEvent(1, n, sh, l); // Calls UtilBaseEventSource.WriteEvent
}
public static class Keywords
{
public const EventKeywords Kwd1 = (EventKeywords)1;
}
}public abstract class UtilBaseEventSource : EventSource
{
protected UtilBaseEventSource() : base() { }
protected UtilBaseEventSource(bool throwOnEventWriteErrors) : base(throwOnEventWriteErrors) { }
protected unsafe void WriteEvent(int eventId, int arg1, short arg2, long arg3)
{
if (IsEnabled())
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
descrs[0].DataPointer = (IntPtr)(&arg1);
descrs[0].Size = 4;
descrs[1].DataPointer = (IntPtr)(&arg2);
descrs[1].Size = 2;
descrs[2].DataPointer = (IntPtr)(&arg3);
descrs[2].Size = 8;
WriteEventCore(eventId, 3, descrs);
}
}
}
[EventSource(Name = "OptimizedEventSource")]
public sealed class OptimizedEventSource : UtilBaseEventSource
{
public static OptimizedEventSource Log = new OptimizedEventSource();
[Event(1, Keywords = Keywords.Kwd1, Level = EventLevel.Informational,
Message = "LogElements called {0}/{1}/{2}.")]
public void LogElements(int n, short sh, long l)
{
WriteEvent(1, n, sh, l); // Calls UtilBaseEventSource.WriteEvent
}
public static class Keywords
{
public const EventKeywords Kwd1 = (EventKeywords)1;
}
}The EventSource class is available in two primary forms:
mscorlib.dll (starting from .NET 4.5) in the System.Diagnostics.Tracing namespace.Microsoft.Diagnostics.Tracing.EventSource): Contains features from v4.5.1+ (like activity tracing and ETW channel support). This package uses the Microsoft.Diagnostics.Tracing namespace.Use the NuGet package if you need advanced features on .NET v4.0 or if you want to access new features before they are integrated into the core framework.
In the context of ETW, it is important to distinguish between these two concepts:
wevtutil or attaching it to a DLL). It updates a system-wide database so names and keyword descriptions can be looked up.EventProvider starts running (e.g., an EventSource is instantiated). The provider registers its unique GUID with the OS. This allows the OS to track which providers are currently active or available for a session to enable.Note on EventSources: EventSource instances do not automatically publish manifests via the standard wevtutil mechanism, which means they may not appear in logman query providers lists, even though they are registered with the OS via their GUID.