Skip to content

Can't use System.Diagnostic.Tracing.EventSource based classes in .NET Core for Linux #27635

Closed

Description

@ghost

The code is here:

https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

When I try to use EventSource execution fails with "Exception during construction of EventSource Microsoft-Diagnostics-DiagnosticSource: Unsupported type IEnumerable`1 in event source.".
It looks like IEnumerable parameters aren't supported in .NET Core for Linux.

Activity

  1. stephentoub commented on Oct 15, 2018

    @stephentoub
    Member
  2. karelz commented on Oct 16, 2018

    @karelz
    Member
  3. noahfalk commented on Oct 16, 2018

    @noahfalk
    Member

    Adding @jorive

    Do you have a repro code for how you are using DiagnosticsSource?

    What sort of 'fail' are you seeing exactly? Does the application crash with an unhandled exception? (And if so can you include the stack trace from the exception please) On Windows I can also get a sample app to throw an ArgumentException with that text, but the exception is handled and it doesn't cause the app to crash. If you are seeing different failure behavior I don't know if that is because you used DiagnosticsSource differently, or because Windows vs. Linux difference, or something else.

  4. vancem commented on Oct 17, 2018

    @vancem

    We definitely want to see the repro in more detail (you should be able to make a small one). Note that EventSource DOES support IEnumerable, but the argument type has to be serializable by EventSource (thus a primitive type, or string, or class that was declared with the EventDataAttribute.

    What is the type that you are trying to pass? It is an IEnumerable of what?

  5. noahfalk commented on Oct 17, 2018

    @noahfalk
    Member

    I'm not sure if this issue is related to the OP or not, but here is a repro that throws a 1st chance exception and catches it. The issue in this case is that ManifestBuilder has no support for IEnumerable, regardless of what type it is instantiated over.

    using System.Collections.Generic;
    using System.Diagnostics.Tracing;
    
    namespace Repro32822
    {
        class Program
        {
            static void Main(string[] args)
            {
                MyEventSource source = new MyEventSource();
                EventListener l = new MyEventListener();
                l.EnableEvents(source, EventLevel.Verbose, EventKeywords.All);
                source.Event("hi", "there", new int[] { 1 });
            }
        }
    
        public class MyEventListener : EventListener
        {
        }
    
        public class MyEventSource : EventSource
        {
            public MyEventSource() { }
            public void Event(string SourceName, string EventName, IEnumerable<int> Arguments)
            {
                WriteEvent(1, SourceName, EventName, Arguments);
            }
        }
    }
    

    The exception is:
    Exception thrown: 'System.ArgumentException' in System.Private.CoreLib.dll
    Unsupported type IEnumerable`1 in event source.

    At callstack:

    System.Private.CoreLib.dll!System.Diagnostics.Tracing.ManifestBuilder.GetTypeNameHelper(System.Type type) Line 189 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.ManifestBuilder.AddEventParameter(System.Type type, string name) Line 5161 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.CreateManifestAndDescriptors(System.Type eventSourceType, string eventSourceDllName, System.Diagnostics.Tracing.EventSource source, System.Diagnostics.Tracing.EventManifestOptions flags) Line 3099 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.EnsureDescriptorsInitialized() Line 2612 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.DoCommand(System.Diagnostics.Tracing.EventCommandEventArgs commandArgs) Line 2398 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.SendCommand(System.Diagnostics.Tracing.EventListener listener, int perEventSourceSessionId, int etwSessionId, System.Diagnostics.Tracing.EventCommand command, bool enable, System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords matchAnyKeyword, System.Collections.Generic.IDictionary<string, string> commandArguments) Line 2358 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventListener.EnableEvents(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords matchAnyKeyword, System.Collections.Generic.IDictionary<string, string> arguments) Line 3887 C#
    System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventListener.EnableEvents(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords matchAnyKeyword) Line 3866 C#
    Repro32822.dll!Repro32822.Program.Main(string[] args) Line 12 C#

  6. vancem commented on Oct 17, 2018

    @vancem

    @noahfalk you need to tweek your example slightly. By default (because of compat), The normal WriteEvent APIs assume you want to emit your events as Manifest-based events, and these do not support IEnumerable. However, if you change the constructor of MyEventSource to this

    private MyEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { }
    

    It tells EventSource that you want to use the self-describing format, which DOES support IEnumerable. Try that. (Note that DiagnosticEventSource does do this). I expect this to to work.

    Note you can't pass an arbitrary IEnumerable to the EventSource, it has to be an IEnuemrable of a type that is Serializable (from EventSource's point of view). This means it is either a primitive type, a string (a few other things like Nullable, and DateTime), or a class that has been marked with the EventData attribute and has properties that are in turn serializable.

    Note that my strong suspicion is that in the orginal bug report what was passed was an IEnumerable where the element type did not conform to these rules.

  7. vancem commented on Oct 18, 2018

    @vancem

    This case does not even have an IEnumerable. I would have expected it to work.
    @noahfalk can you take a look?

    @goodvinj - if you can simplify the case even more (e.g remove whatever event does not cause the probem as well as the NonEvent method, and see if removing the [Event] attribute matters, that would be helpful. The smaller the repro the better.

  8. noahfalk commented on Oct 18, 2018

    @noahfalk
    Member

    @jorive is looking into some of these EventSource bugs, but just a heads up we've already got quite a few in the queue that have shown up recently so it may take a little while to get to this one.

  9. Anipik commented on Feb 22, 2019

    @Anipik
    Contributor

    @jorive any update on this issue ?

  10. jorive commented on Feb 22, 2019

    @jorive

    @Anipik I have not started looking at this issue yet. Could you please provide me with a full repro and I'll start looking into it. On the other hand, what flavor of Linux are you using?

  11. jorive commented on Feb 27, 2019

    @jorive

    @goodvinj Do you have a repro for this issue?

  12. assigned and unassigned on Apr 17, 2019
  13. tommcdon commented on Apr 17, 2019

    @tommcdon
    Member

    load balance to @josalem

  14. transferred this issue fromdotnet/corefxon Jan 31, 2020
  15. added this to the Future milestone on Jan 31, 2020
  16. added
    untriaged
    on Feb 23, 2020
  17. removed
    untriaged
    on Apr 6, 2020
  18. stephentoub commented on May 7, 2020

    @stephentoub
    Member

    The original poster of this issue deleted their account and is now a "ghost", and no repro was provided in response to a request, so I'm going to close this issue. Thanks.

  19. ghost locked as resolved and limited conversation to collaborators on Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions