SHARE
TWEET

EventSource Rich Data Payload IEnumerable<T> bug

a guest Oct 14th, 2015 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /// <summary>
  2.  /// There is a bug in the 1.1.26 release of the package. The following code is taken from the documentation in http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-64-26-84/EventSourceRichPayloads.docx
  3. /// See the last 3 lines of the main method
  4. /// </summary>
  5.  
  6. using Microsoft.Diagnostics.Tracing;
  7. using System.Collections.Generic;
  8.  
  9. namespace DriveMappingTest
  10. {
  11.     [EventData]
  12.     public sealed class NodeData
  13.     {
  14.         public string NodeName { get; set; }
  15.         public int NodeId { get; set; }
  16.         public int[] ChildNodeIds { get; set; }
  17.         public Dictionary<string, int> UserValues { get; set; }
  18.     }
  19.  
  20.     [EventData]
  21.     public sealed  class SimpleData
  22.     {
  23.         public string Name { get; set; }
  24.         public int Address { get; set; }
  25.     }
  26.  
  27.  
  28.     //[EventSource(Name = "Samples-EventSourceDemos-RuntimeDemo")]
  29.     public sealed class RuntimeDemoEventSource : EventSource
  30.     {
  31.         // define the Load Event.  Calling this method logs the event
  32.         [NonEvent]
  33.         public void LogSimpleData(string message, SimpleData data) { Write(message, data); }
  34.         [NonEvent]
  35.         public void LogArray(string message, IEnumerable<int> data) { Write(message, data); }
  36.         [NonEvent]
  37.         public void LogNode(string message, NodeData data) { Write(message, data); }
  38.         [NonEvent]
  39.         public void LogDictionary(string message, Dictionary<string, int> keyValues)
  40.         { Write(message, keyValues); }
  41.  
  42.         // define the singleton instance of the event source
  43.         public static RuntimeDemoEventSource Log = new RuntimeDemoEventSource();
  44.  
  45.         private RuntimeDemoEventSource() : base("EventSource-TestSource", EventSourceSettings.EtwSelfDescribingEventFormat) { }
  46.     }
  47.  
  48.     /// <summary>
  49.     /// The following code is taken from the documentation in http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-64-26-84/EventSourceRichPayloads.docx
  50.     /// See the last 3 lines of the main method
  51.     /// </summary>
  52.     public class Test
  53.     {
  54.         static void Main(string[] args)
  55.         {
  56.             var aList = new List<int>() { 3, 4, 5, 6 };
  57.             var aDictionary = new Dictionary<string, int>() { { "user1", 1 }, { "user2", 2 } };
  58.             var aNode = new NodeData
  59.             {
  60.                 NodeName = "Test",
  61.                 NodeId = 1,
  62.                 ChildNodeIds = new int[] { 3, 4, 5 },
  63.                 UserValues = aDictionary
  64.             };
  65.  
  66.             // Logging the complex values above.  
  67.             RuntimeDemoEventSource.Log.LogArray("testMessage", aList);            // EventSourceException: System.ArgumentNullException:This usually means that the object passed to Write is of a type that does not support being used as the top-level object in an event, e.g. a primitive or built-in type. Parameter name: name
  68.             RuntimeDemoEventSource.Log.LogDictionary("testMessage", aDictionary); // EventSourceException: System.ArgumentNullException:This usually means that the object passed to Write is of a type that does not support being used as the top-level object in an event, e.g. a primitive or built-in type. Parameter name: name
  69.             RuntimeDemoEventSource.Log.LogNode("testMessage", aNode);             // Logged successfully.
  70.         }
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top