jonwagner / EventSourceProxy

EventSourceProxy (ESP) is the easiest way to add scalable Event Tracing for Windows (ETW) logging to your .NET program
Other
97 stars 20 forks source link

Tracing throws NullRefException when using null parameter #43

Closed hutterm closed 3 years ago

hutterm commented 9 years ago

Here is a minimal test case - it throws on the last line:

    public class Test
    {
        public int Int;
    }

    public interface IInterface
    {
        void TraceTest(Test t);
    }

    [TestMethod]
    public void TraceTest()
    {
        TraceParameterProvider.Default.ForAnything().With<Test>().Trace(test => test.Int).EndWith();
        var iinterface = EventSourceImplementer.GetEventSourceAs<IInterface>();
        var _listener = new TestEventListener();
        _listener.EnableEvents((EventSource)iinterface, EventLevel.LogAlways);
        iinterface.TraceTest(null);
    }

I haven't found a clever way to get around that easily. Can you handle this special case internally?

mjeanrichard commented 8 years ago

I think you could use TraceParameterProvider.Default.ForAnything().With<Test>().Trace(test => test == null ? 0 : test.Int).EndWith() That should prevent the NullRef.

jonwagner commented 3 years ago

This is fixed in 4.0.0 running against net46/netstandard2.0