Skip to content

EventSource passing wrong byte[] data to listener #6181

@stephentoub

Description

@stephentoub

Repro:

using System;
using System.Diagnostics.Tracing;

class Program
{
    static void Main()
    {
        var source = new MySource();
        var listener = new MyListener();
        source.Data(new byte[] { 1, 2, 3, 4, 5 });
    }
}

class MySource : EventSource
{
    [Event(1)]
    public void Data(byte[] data) => WriteEvent(1, data);
}

class MyListener : EventListener
{
    protected override void OnEventSourceCreated(EventSource eventSource) =>
        EnableEvents(eventSource, EventLevel.Verbose);

    protected override void OnEventWritten(EventWrittenEventArgs eventData)
    {
        foreach (var item in eventData.Payload)
        {
            byte[] data = item as byte[];
            if (data != null)
            {
                Console.WriteLine("Data: " + string.Join(",", data));
            }
        }
    }
}

This should print out Data: 1, 2, 3, 4, 5. Instead it prints out Data: 1, 1, 1, 1, 1.

This repros for me on both the .NET Framework and .NET Core.

cc: @davmason, @vancem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions