Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

KernelTraceEventParser.All generates System.InvalidCastException #29

Open

Description

The exception occurs on the .NET 3.5 runtime but not the .NET 4.0+ runtime, when executing the line "source.Kernel.All += Print;" in the sample code, below. Neither the same code nor my code doing something very similar work.

static void DataProcessing(string dataFileName)
    {
        Out.WriteLine("Opening the output file and printing the results.");
        using (var source = new ETWTraceEventSource(dataFileName))
        {
            if (source.EventsLost != 0)
                Out.WriteLine("WARNING: there were {0} lost events", source.EventsLost);

            // Set up callbacks to 
            source.Clr.All += Print;
            source.Kernel.All += Print;
        ...

Here is the Exception:

System.InvalidCastException occurred
Message=Unable to cast object of type 'System.Action1[Microsoft.Diagnostics.Tracing.TraceEvent]' to type 'System.Action1[Microsoft.Diagnostics.Tracing.Parsers.Kernel.EventTraceHeaderTraceData]'.
Source=Microsoft.Diagnostics.Tracing.TraceEvent
StackTrace:
at Microsoft.Diagnostics.Tracing.Parsers.Kernel.EventTraceHeaderTraceData.set_Target(Delegate value)
at Microsoft.Diagnostics.Tracing.TraceEventParser.Subscribe(SubscriptionRequest cur, TraceEvent template, Object templateState, Boolean mayHaveExistedBefore)
at Microsoft.Diagnostics.Tracing.TraceEventParser.<>c__DisplayClassb.b__a(TraceEvent template)
at Microsoft.Diagnostics.Tracing.Parsers.KernelTraceEventParser.EnumerateTemplates(Func3 eventsToObserve, Action1 callback)
at WindowsEtwDataCollector.EtwDataCollector.RunKernelTrace(ConditionChecker shouldAbort) in C:\dev\vault\Vault\DataCollectors\WindowsEtwDataCollector\EtwDataCollector.cs:line 174
InnerException:

Microsoft.Diagnostics.Tracing.Parsers.Kernel.EventTraceHeaderTraceData
.. is derived from ...
Microsoft.Diagnostics.Tracing.TraceEvent

System.InvalidCastException occurred
Message=Unable to cast object of type 'System.Action1[Microsoft.Diagnostics.Tracing.TraceEvent]' to type 'System.Action1[Microsoft.Diagnostics.Tracing.Parsers.Kernel.EventTraceHeaderTraceData]'.
Source=Microsoft.Diagnostics.Tracing.TraceEvent
StackTrace:
at Microsoft.Diagnostics.Tracing.Parsers.Kernel.EventTraceHeaderTraceData.set_Target(Delegate value)
at Microsoft.Diagnostics.Tracing.TraceEventParser.Subscribe(SubscriptionRequest cur, TraceEvent template, Object templateState, Boolean mayHaveExistedBefore)
at Microsoft.Diagnostics.Tracing.TraceEventParser.<>c__DisplayClassb.b__a(TraceEvent template)
at Microsoft.Diagnostics.Tracing.Parsers.KernelTraceEventParser.EnumerateTemplates(Func3 eventsToObserve, Action1 callback)
at WindowsEtwDataCollector.EtwDataCollector.RunKernelTrace(ConditionChecker shouldAbort) in C:\dev\vault\Vault\DataCollectors\WindowsEtwDataCollector\EtwDataCollector.cs:line 174
InnerException:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions