Is DateTime allowed as a parameter?

Topics: Semantic Logging Application Block
Mar 19, 2014 at 11:59 PM
I have this code:
if (IsEnabled()) WriteEvent(17, sessionId, personId, startDate, endDate, data, message);
If I pass the dates as strings, everything is fine. But if startDate and endDate are dates, I get this error below.

What types are allowed in the WriteEvent method?


String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

[FormatException: String was not recognized as a valid DateTime.]
System.DateTime.Parse(String s, IFormatProvider provider) +14127602
System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +224

[FormatException: 1 is not a valid value for DateTime.]
System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +3484426
System.ComponentModel.TypeConverter.ConvertFromInvariantString(String text) +53
Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility.TypeExtensions.NotDefault(Type type) +191
Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility.EventSourceAnalyzer.TryInvokeMethod(EventSchema eventSchema, EventSource source, ProbeEventListener listener, MethodInfo& method) +377
Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility.EventSourceAnalyzer.ProbeEvent(EventSchema eventSchema, EventSource source) +153
Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility.EventSourceAnalyzer.Inspect(EventSource eventSource) +164
SecureHealthHub.Peachy.Web.Application.Application_Start() in c:\Development\shh\SecureHealthHub\PeachyWebApi\Global.asax.cs:41

[HttpException (0x80004005): 1 is not a valid value for DateTime.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12584889
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): 1 is not a valid value for DateTime.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12601920
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12441581
Mar 20, 2014 at 12:04 AM
I wrote about the valid types in this thread. To sum up the current valid types are:
Boolean, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, String, Guid.
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by matthewpomar on 3/19/2014 at 4:32 PM
Mar 20, 2014 at 12:33 AM
Thanks Randy!

I looked for this information, but couldn't find it. I appreciate the prompt reply.

Adding the valid types as a comment so I don't have to look (ask) again. :)

Matt
Jan 3, 2015 at 6:37 PM
For the benefit of anyone getting here from a web search, there are now additional valid types:

The .NET version currently supports the following types (taken from ManifestBuilder.GetTypeName):
Enum, Boolean, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, DateTime, String, Guid
(Note that while DateTime is supported, EventSourceAnalyzer will report an error)

The NuGet distribution adds support for the following types:
Char, IntPtr, Byte*, Byte[]

For more information see http://ohadsc.wordpress.com/2014/10/13/getting-started-with-etw-using-nets-eventsource/