Fix spurious warning about parameter counts
authorDavid Mason <davmason@microsoft.com>
Thu, 24 Mar 2016 17:48:51 +0000 (10:48 -0700)
committerDavid Mason <davmason@microsoft.com>
Thu, 24 Mar 2016 18:01:16 +0000 (11:01 -0700)
src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs

index be72b54..218826a 100644 (file)
@@ -2117,12 +2117,34 @@ namespace System.Diagnostics.Tracing
 #endif //!ES_BUILD_PCL
         }
 
+        private int GetParamLenghtIncludingByteArray(ParameterInfo[] parameters)
+        {
+            int sum = 0;
+            foreach(ParameterInfo info in parameters)
+            {
+                if(info.ParameterType == typeof(byte[]))
+                {
+                    sum += 2;
+                }
+                else
+                {
+                    sum++;
+                }
+            }
+
+            return sum;
+        }
+
         [SecurityCritical]
         unsafe private void WriteToAllListeners(int eventId, Guid* childActivityID, int eventDataCount, EventSource.EventData* data)
         {
-            int paramCount = GetParameterCount(m_eventData[eventId]);
-            
-            if (eventDataCount != paramCount)
+            // We represent a byte[] as a integer denoting the length  and then a blob of bytes in the data pointer. This causes a spurious
+            // warning because eventDataCount is off by one for the byte[] case since a byte[] has 2 items associated it. So we want to check
+            // that the number of parameters is correct against the byte[] case, but also we the args array would be one too long if
+            // we just used the modifiedParamCount here -- so we need both.
+            int paramCount = m_eventData[eventId].Parameters.Length;
+            int modifiedParamCount = GetParamLenghtIncludingByteArray(m_eventData[eventId].Parameters);
+            if (eventDataCount != modifiedParamCount)
             {
                 ReportOutOfBandMessage(Resources.GetResourceString("EventSource_EventParametersMismatch", eventId, eventDataCount, paramCount), true);
                 paramCount = Math.Min(paramCount, eventDataCount);