NullReferenceException in WCF module


#1

MiniProfiler 2.0.4 + WCF module. This only happens when I stress test my application with JMeter, cannot reproduce it when doing manual testing. .NET 4.5, MVC 3, Windows 7 x64

System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace: 
   at StackExchange.Profiling.Timing.<get_HasDuplicateSqlTimings>b__2(SqlTiming s) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\Timing.cs:line 173
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at StackExchange.Profiling.MiniProfiler.OnDeserialized(StreamingContext ctx) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\MiniProfiler.cs:line 392
   at ReadMiniProfilerFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
   at ReadMiniProfilerResultsHeaderFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
   at System.ServiceModel.Channels.MessageHeaders.GetHeader[T](Int32 index, XmlObjectSerializer serializer)
   at System.ServiceModel.Channels.MessageHeaders.GetHeader[T](Int32 index)
   at StackExchange.Profiling.Wcf.WcfMiniProfilerClientInspector.AfterReceiveReply(Message& reply, Object correlationState) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling.Wcf\WcfMiniProfilerClientInspector.cs:line 82
   at System.ServiceModel.Dispatcher.ImmutableClientRuntime.AfterReceiveReply(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

#2

Same conditions, different exception. Looks like the code isn’t thread safe :frowning:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.Generic.List`1.Add(T item)
   at StackExchange.Profiling.Timing.AddSqlTiming(SqlTiming sqlTiming) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\Timing.cs:line 332
   at StackExchange.Profiling.MiniProfiler.AddSqlTiming(SqlTiming stats) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\MiniProfiler.IDbProfiler.cs:line 97
   at StackExchange.Profiling.SqlTiming..ctor(IDbCommand command, ExecuteType type, MiniProfiler profiler) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\SqlTiming.cs:line 135
   at StackExchange.Profiling.SqlProfiler.ExecuteStartImpl(IDbCommand command, ExecuteType type) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\SqlProfiler.cs:line 39
   at StackExchange.Profiling.MiniProfiler.StackExchange.Profiling.Data.IDbProfiler.ExecuteStart(IDbCommand profiledDbCommand, ExecuteType executeType) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\MiniProfiler.IDbProfiler.cs:line 116
   at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Projects\SamSaffron-MiniProfiler-76b4d91\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 160
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.CompiledQuery.Execute(IProvider provider, Object[] arguments)