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

InvalidOperationException with two Parameters of the same Type #55

Closed mjeanrichard closed 3 years ago

mjeanrichard commented 8 years ago

The following Code results in an InvalidOperationException. If I remove one parameter from the Message or change the type of one of the parameters everything works fine. The Error only happens when I configure a custom TraceParameter (see example).

using System;
using System.Diagnostics.Tracing;
using EventSourceProxy;

namespace ConsoleApplication2
{
    [EventSourceImplementation(Name = "Test", ImplementComplementMethods = false)]
    public interface ITestEvents
    {
        [Event(100, Message = "Test {0}, {1}.", Level = EventLevel.Verbose)]
        void MyLog(Type t, Type t2);
    }

    class Program
    {
        static void Main(string[] args)
        {
            TraceParameterProvider.Default.ForAnything().With<Type>().Trace(t => t.FullName);
            EventSourceImplementer.GetEventSourceAs<ITestEvents>().MyLog(typeof(string), typeof(int));
        }
    }
}
System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=Invalid string format in Log Method MyLog
  Source=EventSourceProxy
  StackTrace:
       at EventSourceProxy.TypeImplementer.ValidateEventMessage(EventAttribute eventAttribute, MethodInfo method, List`1 parameters)
       at EventSourceProxy.TypeImplementer.EmitMethodImpl(InvocationContext invocationContext, Int32& eventId, EventKeywords autoKeyword)
       at EventSourceProxy.TypeImplementer.ImplementType()
       at EventSourceProxy.TypeImplementer..ctor(Type interfaceType, TraceParameterProvider parameterProvider)
       at EventSourceProxy.EventSourceImplementer.<GetEventSource>b__1(Type t)
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
       at EventSourceProxy.EventSourceImplementer.GetEventSource(Type type)
       at EventSourceProxy.EventSourceImplementer.GetEventSourceAs[T]()
       at ConsoleApplication2.Program.Main(String[] args) in D:\git\ConsoleApplication2\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233033
       Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
       Source=mscorlib
       StackTrace:
            at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
            at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
            at System.String.Format(IFormatProvider provider, String format, Object[] args)
            at EventSourceProxy.TypeImplementer.ValidateEventMessage(EventAttribute eventAttribute, MethodInfo method, List`1 parameters)
jonwagner commented 3 years ago

Looks like the issue is that a function applied to a type, and the type is used twice in the parameter list, and the processing is treating them as the same parameter.

jonwagner commented 3 years ago

Should be fixed in 4.0.0