Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug.Assert exception I encountered when using Debug version System.Private.CoreLib.dll with mono runtime #96324

Closed
bodong1987 opened this issue Dec 27, 2023 · 9 comments · Fixed by #105341
Assignees
Labels
area-System.Diagnostics.Tracing needs-author-action An issue or pull request that requires more info or actions from the author. runtime-mono specific to the Mono runtime

Comments

@bodong1987
Copy link

Description

I was testing integrating the Mono Runtime into my C++ application and encountered the following problem during the initialization phase:

   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()

In order to find this problem, I modified the source code locally and output the log when necessary. The code modification is as follows:

public event EventHandler<EventCommandEventArgs>? EventCommandExecuted
{
    add
    {
        if (value == null)
            return;

        Debug.WriteLine($"EventSource[{GetHashCode()}] add new one {value}({value.GetHashCode()}) from {System.Environment.StackTrace}");

        m_eventCommandExecuted += value;

        // If we have an EventHandler<EventCommandEventArgs> attached to the EventSource before the first command arrives
        // It should get a chance to handle the deferred commands.
        EventCommandEventArgs? deferredCommands = m_deferredCommands;
        while (deferredCommands != null)
        {
            Debug.WriteLine($"EventSource[{GetHashCode()}]Invoke deferred command on this value:{deferredCommands}({deferredCommands.GetHashCode()} Command = {deferredCommands.Command})");

            value(this, deferredCommands);
            deferredCommands = deferredCommands.nextCommand;
        }
    }
    remove
    {
        Debug.WriteLine($"EventSource[{GetHashCode()}] remove one {value} from {System.Environment.StackTrace}");

        m_eventCommandExecuted -= value;
    }
}
internal void SendCommand(EventListener? listener, EventProviderType eventProviderType, int perEventSourceSessionId,
                          EventCommand command, bool enable,
                          EventLevel level, EventKeywords matchAnyKeyword,
                          IDictionary<string, string?>? commandArguments)
{
    if (!IsSupported)
    {
        return;
    }

    var commandArgs = new EventCommandEventArgs(command, commandArguments, this, listener, eventProviderType, perEventSourceSessionId, enable, level, matchAnyKeyword);
    lock (EventListener.EventListenersLock)
    {
        if (m_completelyInited)
        {
            // After the first command arrive after construction, we are ready to get rid of the deferred commands
            this.m_deferredCommands = null;
            // We are fully initialized, do the command
            DoCommand(commandArgs);
        }
        else
        {
            Debug.WriteLine($"EventSource[{GetHashCode()}] Add {commandArgs} {commandArgs.GetHashCode()} Command={commandArgs.Command} to m_deferredCommands in SendCommand:\r\n{System.Environment.StackTrace}");

            // We can't do the command, simply remember it and we do it when we are fully constructed.
            if (m_deferredCommands == null)
            {
                m_deferredCommands = commandArgs;       // create the first entry
            }
            else
            {
                // We have one or more entries, find the last one and add it to that.
                EventCommandEventArgs lastCommand = m_deferredCommands;
                while (lastCommand.nextCommand != null)
                    lastCommand = lastCommand.nextCommand;
                lastCommand.nextCommand = commandArgs;
            }
        }
    }
}

I added the log and found that the reason was because some Update type Commands were added to m_deferredCommands in advance in EventSource.Initialize. When the code runs to CounterGroup.RegisterCommandCallback, it tries to trigger the command in m_deferredCommands, and then Assert is triggered.

EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -923182367 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -1572497824 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs 1959724822 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -204200971 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -173953956 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs -1391687009 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs 663802102 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs 965942388 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] add new one System.EventHandler`1[System.Diagnostics.Tracing.EventCommandEventArgs](70175282) from    at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(-1391687009 Command = Enable)
EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(663802102 Command = Update)
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
command is:Update, need Enable or Disable.
---- Assert Long Message ----

   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
Process terminated. Assertion failed.
command is:Update, need Enable or Disable.
   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()

this code is invoked from native mono code:ep_rt_mono_init_finish

void
ep_rt_mono_init_finish (void)
{
	if (mono_runtime_get_no_exec ())
		return;

	// Managed init of diagnostics classes, like registration of RuntimeEventSource (if available).
	ERROR_DECL (error);

	MonoClass *runtime_event_source = mono_class_from_name_checked (mono_get_corlib (), "System.Diagnostics.Tracing", "RuntimeEventSource", error);
	if (is_ok (error) && runtime_event_source) {
		MonoMethod *init = mono_class_get_method_from_name_checked (runtime_event_source, "Initialize", -1, 0, error);
		if (is_ok (error) && init) {
			mono_runtime_try_invoke_handle (init, NULL_HANDLE, NULL, error);
		}
	}

	mono_error_cleanup (error);
}

Reproduction Steps

  1. build mono runtime/libs with debug configuration
  2. Directly use mono_jit_init_version to initialize mono runtime

Expected behavior

no Debug.Assert

Actual behavior

 Debug.Assert(e.Command == EventCommand.Enable || e.Command == EventCommand.Disable); 

in CounterGroup.OnEventSourceCommand.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 27, 2023
@ghost
Copy link

ghost commented Dec 27, 2023

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I was testing integrating the Mono Runtime into my C++ application and encountered the following problem during the initialization phase:

   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()

In order to find this problem, I modified the source code locally and output the log when necessary. The code modification is as follows:

public event EventHandler<EventCommandEventArgs>? EventCommandExecuted
{
    add
    {
        if (value == null)
            return;

        Debug.WriteLine($"EventSource[{GetHashCode()}] add new one {value}({value.GetHashCode()}) from {System.Environment.StackTrace}");

        m_eventCommandExecuted += value;

        // If we have an EventHandler<EventCommandEventArgs> attached to the EventSource before the first command arrives
        // It should get a chance to handle the deferred commands.
        EventCommandEventArgs? deferredCommands = m_deferredCommands;
        while (deferredCommands != null)
        {
            Debug.WriteLine($"EventSource[{GetHashCode()}]Invoke deferred command on this value:{deferredCommands}({deferredCommands.GetHashCode()} Command = {deferredCommands.Command})");

            value(this, deferredCommands);
            deferredCommands = deferredCommands.nextCommand;
        }
    }
    remove
    {
        Debug.WriteLine($"EventSource[{GetHashCode()}] remove one {value} from {System.Environment.StackTrace}");

        m_eventCommandExecuted -= value;
    }
}
internal void SendCommand(EventListener? listener, EventProviderType eventProviderType, int perEventSourceSessionId,
                          EventCommand command, bool enable,
                          EventLevel level, EventKeywords matchAnyKeyword,
                          IDictionary<string, string?>? commandArguments)
{
    if (!IsSupported)
    {
        return;
    }

    var commandArgs = new EventCommandEventArgs(command, commandArguments, this, listener, eventProviderType, perEventSourceSessionId, enable, level, matchAnyKeyword);
    lock (EventListener.EventListenersLock)
    {
        if (m_completelyInited)
        {
            // After the first command arrive after construction, we are ready to get rid of the deferred commands
            this.m_deferredCommands = null;
            // We are fully initialized, do the command
            DoCommand(commandArgs);
        }
        else
        {
            Debug.WriteLine($"EventSource[{GetHashCode()}] Add {commandArgs} {commandArgs.GetHashCode()} Command={commandArgs.Command} to m_deferredCommands in SendCommand:\r\n{System.Environment.StackTrace}");

            // We can't do the command, simply remember it and we do it when we are fully constructed.
            if (m_deferredCommands == null)
            {
                m_deferredCommands = commandArgs;       // create the first entry
            }
            else
            {
                // We have one or more entries, find the last one and add it to that.
                EventCommandEventArgs lastCommand = m_deferredCommands;
                while (lastCommand.nextCommand != null)
                    lastCommand = lastCommand.nextCommand;
                lastCommand.nextCommand = commandArgs;
            }
        }
    }
}

I added the log and found that the reason was because some Update type Commands were added to m_deferredCommands in advance in EventSource.Initialize. When the code runs to CounterGroup.RegisterCommandCallback, it tries to trigger the command in m_deferredCommands, and then Assert is triggered.

EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -923182367 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -1572497824 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs 1959724822 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -204200971 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[-1243760484] Add System.Diagnostics.Tracing.EventCommandEventArgs -173953956 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs -1391687009 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs 663802102 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] Add System.Diagnostics.Tracing.EventCommandEventArgs 965942388 Command=Update to m_deferredCommands in SendCommand:
   at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments)
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId)
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData)
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext)
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047] add new one System.EventHandler`1[System.Diagnostics.Tracing.EventCommandEventArgs](70175282) from    at System.Environment.get_StackTrace()
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(-1391687009 Command = Enable)
EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(663802102 Command = Update)
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
command is:Update, need Enable or Disable.
---- Assert Long Message ----

   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()
Process terminated. Assertion failed.
command is:Update, need Enable or Disable.
   at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Fail(String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Diagnostics.Debug.Assert(Boolean condition, String message)
   at System.Diagnostics.Debug.Assert(Boolean condition, AssertInterpolatedStringHandler& message)
   at System.Diagnostics.Tracing.CounterGroup.OnEventSourceCommand(Object sender, EventCommandEventArgs e)
   at System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(EventHandler`1 value)
   at System.Diagnostics.Tracing.CounterGroup.RegisterCommandCallback()
   at System.Diagnostics.Tracing.CounterGroup..ctor(EventSource eventSource)
   at System.Diagnostics.Tracing.CounterGroup.GetCounterGroup(EventSource eventSource)
   at System.Diagnostics.Tracing.DiagnosticCounter.Publish()
   at System.Diagnostics.Tracing.PollingCounter..ctor(String name, EventSource eventSource, Func`1 metricProvider)
   at System.Diagnostics.Tracing.RuntimeEventSource.OnEventCommand(EventCommandEventArgs command)
   at System.Diagnostics.Tracing.EventSource.DoCommand(EventCommandEventArgs commandArgs)
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits)
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName)
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor()
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize()

this code is invoked from native mono code:ep_rt_mono_init_finish

void
ep_rt_mono_init_finish (void)
{
	if (mono_runtime_get_no_exec ())
		return;

	// Managed init of diagnostics classes, like registration of RuntimeEventSource (if available).
	ERROR_DECL (error);

	MonoClass *runtime_event_source = mono_class_from_name_checked (mono_get_corlib (), "System.Diagnostics.Tracing", "RuntimeEventSource", error);
	if (is_ok (error) && runtime_event_source) {
		MonoMethod *init = mono_class_get_method_from_name_checked (runtime_event_source, "Initialize", -1, 0, error);
		if (is_ok (error) && init) {
			mono_runtime_try_invoke_handle (init, NULL_HANDLE, NULL, error);
		}
	}

	mono_error_cleanup (error);
}

Reproduction Steps

  1. build mono runtime/libs with debug configuration
  2. Directly use mono_jit_init_version to initialize mono runtime

Expected behavior

no Debug.Assert

Actual behavior

 Debug.Assert(e.Command == EventCommand.Enable || e.Command == EventCommand.Disable); 

in CounterGroup.OnEventSourceCommand.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: bodong1987
Assignees: -
Labels:

area-System.Diagnostics.Tracing, untriaged

Milestone: -

@bodong1987 bodong1987 changed the title Debug.Assert exception I encountered when using Debug Runtime Debug.Assert exception I encountered when using Debug version System.Private.CoreLib.dll with mono runtime Dec 27, 2023
@tommcdon
Copy link
Member

tommcdon commented Jan 2, 2024

@lateralusX is this something that we should investigate in the mono implementation of eventpipe first?

@tommcdon tommcdon added this to the 9.0.0 milestone Jan 6, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 6, 2024
@lateralusX
Copy link
Member

I can take a look, we run this code when running other versions of launchers embedding Mono on both desktop and mobile platforms, so I have not seen this issue in the other embedding scenarios, but need to take a close look to be sure. I know we had some changes around counter implementation in .net8 that potentially might have triggered some regression on Mono side, but we will see. I currently have some other things in pipe line before I can look at this, but try to get to it in coming weeks.

@lateralusX lateralusX self-assigned this Jan 8, 2024
@bodong1987
Copy link
Author

HandleEnableNotification

hello. I found that this problem is indeed not a inevitable problem. If I encounter this problem, I only need to restart the operating system. And this problem seems to only occur on my Windows 10 machine. I have not encountered it on my other Windows 11 machine.
I refined the log more and got more information. It seems that the cause of this problem is the following code:

EtwEventProvider.HandleEnableNotification

This is triggered indirectly through the callback callback of the api calling Interop.Advapi32.EventRegister.

Initialize IsSupported.
Event source constructed... guid=49592c0f-5a05-516d-aa4b-a64e02026c89 eventName=System.Runtime
EtwEventProvider.Register started... guid=49592c0f-5a05-516d-aa4b-a64e02026c89
EtwEventProvider.Callback started... guid=00000000-0000-0000-0000-000000000000
ProviderCallback controlCode=1
HandleEnableNotification
EtwEventProvider HandleEnableNotification...
process session info: 28 5 bEnabling=True
TryReadRegistryFilterData...
invoke OnControllerCommand, command = Update
Event source constructed... guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4 eventName=Microsoft-Windows-DotNETRuntime
EtwEventProvider.Register started... guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4
EtwEventProvider.Callback started... guid=00000000-0000-0000-0000-000000000000
ProviderCallback controlCode=1
HandleEnableNotification
EtwEventProvider HandleEnableNotification...
process session info: 28 5 bEnabling=True
TryReadRegistryFilterData...
invoke OnControllerCommand, command = Update
Event source constructed... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44 eventName=System.Buffers.ArrayPoolEventSource
EtwEventProvider.Register started... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44
EtwEventProvider.Register finished... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44
Event source guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4name=Microsoft-Windows-DotNETRuntime added with m_completelyInited = false, command=Update
   at System.Environment.get_StackTrace() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Environment.cs:line 225
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2588
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2448
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 840
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 1330
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 854
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 871
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 118
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1624
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1575
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1560
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor() in J:\dotnet.runtime.mono\src\mono\System.Private.CoreLib\System.Private.CoreLib.Generators\Generators.EventSourceGenerator\NativeRuntimeEventSource.g.cs:line 12
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\NativeRuntimeEventSource.cs:line 22
   at System.Diagnostics.Tracing.EventListener.get_EventListenersLock() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 4491
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2577
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2448
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 840
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 1330
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 854
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 871
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 118
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1624
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1575
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1560
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor() in J:\dotnet.runtime.mono\src\mono\System.Private.CoreLib\System.Private.CoreLib.Generators\Generators.EventSourceGenerator\RuntimeEventSource.g.cs:line 12
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\RuntimeEventSource.cs:line 69
process session info: 31 5 bEnabling=True
TryReadRegistryFilterData...
invoke OnControllerCommand, command = Update
Event source guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4name=Microsoft-Windows-DotNETRuntime added with m_completelyInited = false, command=Update
   at System.Environment.get_StackTrace() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Environment.cs:line 225
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2588
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2448
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 840
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 1330
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 854
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 871
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 118
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1624
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1575
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1560
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..ctor() in J:\dotnet.runtime.mono\src\mono\System.Private.CoreLib\System.Private.CoreLib.Generators\Generators.EventSourceGenerator\NativeRuntimeEventSource.g.cs:line 12
   at System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\NativeRuntimeEventSource.cs:line 22
   at System.Diagnostics.Tracing.EventListener.get_EventListenersLock() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 4491
   at System.Diagnostics.Tracing.EventSource.SendCommand(EventListener listener, EventProviderType eventProviderType, Int32 perEventSourceSessionId, EventCommand command, Boolean enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary`2 commandArguments) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2577
   at System.Diagnostics.Tracing.EventSource.OverrideEventProvider.OnControllerCommand(ControllerCommand command, IDictionary`2 arguments, Int32 perEventSourceSessionId) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 2448
   at System.Diagnostics.Tracing.EtwEventProvider.HandleEnableNotification(EventProvider target, Byte* additionalData, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 840
   at System.Diagnostics.Tracing.EventProviderImpl.ProviderCallback(EventProvider target, Byte* additionalData, Int32 controlCode, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 1330
   at System.Diagnostics.Tracing.EtwEventProvider.Callback(Guid* sourceId, Int32 isEnabled, Byte level, Int64 matchAnyKeywords, Int64 matchAllKeywords, EVENT_FILTER_DESCRIPTOR* filterData, Void* callbackContext) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 854
   at Interop.Advapi32.EventRegister(Guid* ,  , Void* , Int64* )
   at System.Diagnostics.Tracing.EtwEventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 871
   at System.Diagnostics.Tracing.EventProvider.Register(EventSource eventSource) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs:line 118
   at System.Diagnostics.Tracing.EventSource.Initialize(Guid eventSourceGuid, String eventSourceName, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1624
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName, EventSourceSettings settings, String[] traits) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1575
   at System.Diagnostics.Tracing.EventSource..ctor(Guid eventSourceGuid, String eventSourceName) in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs:line 1560
   at System.Diagnostics.Tracing.RuntimeEventSource..ctor() in J:\dotnet.runtime.mono\src\mono\System.Private.CoreLib\System.Private.CoreLib.Generators\Generators.EventSourceGenerator\RuntimeEventSource.g.cs:line 12
   at System.Diagnostics.Tracing.RuntimeEventSource.Initialize() in J:\dotnet.runtime.mono\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\RuntimeEventSource.cs:line 69
 protected override unsafe void HandleEnableNotification(
                             EventProvider target,
                             byte *additionalData,
                             byte level,
                             long matchAnyKeywords,
                             long matchAllKeywords,
                             Interop.Advapi32.EVENT_FILTER_DESCRIPTOR* filterData)
 {
     Debug.Assert(additionalData == null);

     RuntimeEventSource.Log("EtwEventProvider HandleEnableNotification...");

     // The GetSessions() logic was here to support the idea that different ETW sessions
     // could have different user-defined filters. (I believe it is currently broken.)
     //
     // All this session based logic should be reviewed and likely removed, but that is a larger
     // change that needs more careful staging.
     List<KeyValuePair<SessionInfo, bool>> sessionsChanged = GetChangedSessions();

     foreach (KeyValuePair<SessionInfo, bool> session in sessionsChanged)
     {
         int sessionChanged = session.Key.sessionIdBit;
         bool bEnabling = session.Value;

         // reinitialize args for every session...
         IDictionary<string, string?>? args = null;
         ControllerCommand command = ControllerCommand.Update;

         RuntimeEventSource.Log("process session info: " + session.Key.etwSessionId + " " + session.Key.sessionIdBit + " bEnabling=" + bEnabling);

         // read filter data only when a session is being *added*
         if (bEnabling)
         {
             byte[]? filterDataBytes;
             // if we get more than one session changed we have no way
             // of knowing which one "filterData" belongs to
             if (sessionsChanged.Count > 1 || filterData == null)
             {
                 RuntimeEventSource.Log("TryReadRegistryFilterData...");
                 TryReadRegistryFilterData(session.Key.etwSessionId, out command, out filterDataBytes);
             }
             else
             {
                 RuntimeEventSource.Log("MarshalFilterData...");
                 MarshalFilterData(filterData, out command, out filterDataBytes);
             }
             args = ParseFilterData(filterDataBytes);
         }

         RuntimeEventSource.Log("invoke OnControllerCommand, command = " + command.ToString());

         // execute OnControllerCommand once for every session that has changed.
         // If the sessionId argument is positive it will be sent to the EventSource as an Enable,
         // and if it is negative it will be sent as a disable. See EventSource.DoCommand()
         target.OnControllerCommand(command, args, bEnabling ? sessionChanged : -sessionChanged);
     }
 }

 [UnmanagedCallersOnly]
 private static unsafe void Callback(Guid* sourceId, int isEnabled, byte level,
     long matchAnyKeywords, long matchAllKeywords, Interop.Advapi32.EVENT_FILTER_DESCRIPTOR* filterData, void* callbackContext)
 {
     RuntimeEventSource.Log("EtwEventProvider.Callback started... guid=" + (sourceId!=null? sourceId->ToString():""));

     EtwEventProvider _this = (EtwEventProvider)GCHandle.FromIntPtr((IntPtr)callbackContext).Target!;

     if (_this._eventProvider.TryGetTarget(out EventProvider? target))
     {
         _this.ProviderCallback(target, null, isEnabled, level, matchAnyKeywords, matchAllKeywords, filterData);
     }
 }


 // Register an event provider.
 internal override unsafe void Register(EventSource eventSource)
 {
     Debug.Assert(!_gcHandle.IsAllocated);
     _gcHandle = GCHandle.Alloc(this);

     long registrationHandle = 0;
     _providerId = eventSource.Guid;
     Guid providerId = _providerId;

     RuntimeEventSource.Log($"EtwEventProvider.Register started... guid=" + providerId.ToString());

     uint status = Interop.Advapi32.EventRegister(
         &providerId,
         &Callback,
         (void*)GCHandle.ToIntPtr(_gcHandle),
         &registrationHandle);

     RuntimeEventSource.Log($"EtwEventProvider.Register finished... guid=" + providerId.ToString());

     if (status != 0)
     {
         _gcHandle.Free();
         throw new ArgumentException(Interop.Kernel32.GetMessage((int)status));
     }

     Debug.Assert(_registrationHandle == 0);
     _registrationHandle = registrationHandle;
 }

With this information, what do you think?

@jkotas jkotas added the runtime-mono specific to the Mono runtime label Jan 30, 2024
@bodong1987
Copy link
Author

I can take a look, we run this code when running other versions of launchers embedding Mono on both desktop and mobile platforms, so I have not seen this issue in the other embedding scenarios, but need to take a close look to be sure. I know we had some changes around counter implementation in .net8 that potentially might have triggered some regression on Mono side, but we will see. I currently have some other things in pipe line before I can look at this, but try to get to it in coming weeks.

I have intercepted some logs during normal operation. You can see that during normal operation, no extra EventCommandEventArgs are created and added to m_deferredCommands in advance. I guess that's why, at some point, I run into this problem on my computer.

Initialize IsSupported.
[2043902120]Event source constructed... guid=49592c0f-5a05-516d-aa4b-a64e02026c89 eventName=System.Runtime
EtwEventProvider.Register started... guid=49592c0f-5a05-516d-aa4b-a64e02026c89 hashcode=2043902120
EtwEventProvider.Callback started... guid=00000000-0000-0000-0000-000000000000
ProviderCallback controlCode=1
HandleEnableNotification

EtwEventProvider HandleEnableNotification... depth=1
sessionsChanged count = 2
(1/2) process session info: 28 5 bEnabling=True
TryReadRegistryFilterData...
invoke OnControllerCommand, command = Update
[-1953175207]Event source constructed... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44 eventName=System.Buffers.ArrayPoolEventSource
EtwEventProvider.Register started... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44 hashcode=-1953175207
EtwEventProvider.Register finished... guid=0866b2b8-5cef-5db9-2612-0c0ffd814a44 hashcode=-1953175207
[-392682232]Event source constructed... guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4 eventName=Microsoft-Windows-DotNETRuntime
EtwEventProvider.Register started... guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4 hashcode=-392682232
EtwEventProvider.Callback started... guid=00000000-0000-0000-0000-000000000000
ProviderCallback controlCode=1
HandleEnableNotification

EtwEventProvider HandleEnableNotification... depth=1
sessionsChanged count = 4
(1/4) process session info: 28 5 bEnabling=True
TryReadRegistryFilterData...
invoke OnControllerCommand, command = Update
EtwEventProvider.Register finished... guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4 hashcode=-392682232
EtwEventProvider.Register finished... guid=49592c0f-5a05-516d-aa4b-a64e02026c89 hashcode=2043902120

If this problem occurs again later, I will output some more detailed logs.

@mdh1418
Copy link
Member

mdh1418 commented Feb 15, 2024

Hi @bodong1987, I'm trying to follow the stack traces and logging information you provided (which were helpful).
Do you happen to have a simple setup that can repro the issue that I can try out? What dotnet version are you using?

If I am understanding correctly, during EventSource intialization multiple commands are deferred based on the number of sessions changed while registering the providers based on the stack trace and after initialization, the chain of deferred commands are then executed. So later on in the initialization step, the deferred commands would sequentially be executed through DoCommand where RuntimeEventSource.OnEventCommand would be invoked and EventHandlers will be attached for the counters. I think I can see where the Assert will fail, and I think it is demonstrated in one of your stack trace logging.

It looks like multiple Update commands are being added to m_deferredCommands like

m_deferredCommands = [Command.Update, Command.Update, Command.Update, ..., Command.Update]

and each of which would have their command changed to either EventCommand.Enable or EventCommand.Disable, but as the first command is being processed in the Initialize DoCommand m_deferredCommands loop, we hit the EventHandler attached m_deferredCommands loop where m_deferredCommands now looks like

m_deferredCommands = [Command.Enable, Command.Update, Command.Update, ..., Command.Update]

hence, we see the logging statements in that section twice, where the second one hits the assert because the Command was not updated to Enable like the first one

EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(-1391687009 Command = Enable)
EventSource[2000003047]Invoke deferred command on this value:System.Diagnostics.Tracing.EventCommandEventArgs(663802102 Command = Update)

It seems like in both the stack traces where you demonstrate normal operation and one where there are extra commands added, that HandleEnableNotification is hit, so its not clear to me why in one instance, more Update commands are added to m_deferredCommands when constructing the Microsoft-Windows-DotNETRuntime EventSource. Where in SendCommand is the log line Event source guid=e13c0d23-ccbc-4e12-931b-d9cc2eee27e4name=Microsoft-Windows-DotNETRuntime added with m_completelyInited = false, command=Update located? I'm wondering if maybe something is going awry with EventListener.EventListenersLock because a NativeRuntimeEventSource is kicked off.

Are you still able to get a reliable repro, or after the restart, you don't see the assert fail anylonger?

@mdh1418 mdh1418 added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 20, 2024
@ghost
Copy link

ghost commented Feb 20, 2024

This issue has been marked needs-author-action and may be missing some important information.

Copy link
Contributor

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the 9.0.0 milestone Apr 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Tracing needs-author-action An issue or pull request that requires more info or actions from the author. runtime-mono specific to the Mono runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants