Bug in RaygunClientBase in C#
kswoll
Posted on
Oct 07 2014
The class Mindscape.Raygun4Net.RaygunClientBase
has a bug in its implementation of FlagAsSent
which has the following (decompiled) code:
internal void FlagAsSent(Exception exception)
{
if (exception == null)
return;
exception.Data[(object) "AlreadySentByRaygun"] = (object) true;
}
The problem:
Exception.Data
is a virtual property that can be overridden and return a generic dictionary where the key is not a string. For example, in RabbitMQ, the class BrokerUnreachableException
overrides Data
like so:
public override IDictionary Data
{
get
{
return (IDictionary) new Dictionary<AmqpTcpEndpoint, Exception>(this.m_connectionErrors);
}
}
This causes an exception in the raygun code because it's trying to insert a value in the dictionary with a string
key.
Workarounds:
I surround all invocations to raygun with a try/catch. This is not ideal and also misses the point since Raygun doesn't receive the original error.
Suggested Solution:
Either use a try/catch in FlagAsSent
or check the type of the dictionary to ensure it is not a generic dictionary that prohibits string keys.
Jason Fauchelle
Raygun
Posted on
Oct 07 2014
Hello
Thanks for pointing this out. I'll look at fixing this for the next version very soon.
-Jason Fauchelle
moxplod
Posted on
Oct 21 2014
We are having this problem too ..
How can we follow - when this is fixed so we can get the latest package?
Thanks
Application ID: /LM/W3SVC/1/ROOT
Process ID: 3176
Exception: System.ArgumentException
Message: The value "AlreadySentByRaygun" is not of type "RabbitMQ.Client.AmqpTcpEndpoint" and cannot be used in this generic collection. Parameter name: key
StackTrace: at System.ThrowHelper.ThrowWrongKeyTypeArgumentException(Object key, Type targetType)
at System.Collections.Generic.Dictionary2.System.Collections.IDictionary.set_Item(Object key, Object value)
at Mindscape.Raygun4Net.RaygunClient.FlagAsSent(Exception exception) in e:\Users\Jason\Documents\GitHub\raygun4net\Mindscape.Raygun4Net\RaygunClient.cs:line 269
at Mindscape.Raygun4Net.RaygunClient.SendInBackground(Exception exception, IList
1 tags, IDictionary userCustomData) in e:\Users\Jason\Documents\GitHub\raygun4net\Mindscape.Raygun4Net\RaygunClient.cs:line 246
at Insightly.Core.Queue.Dispatcher.QueueMessageDispatcher.<>cDisplayClass1.0(Object o) in c:\TeamCity\buildAgent\work\a143f4b26d146d88\InsightlyCore\Insightly.Core\Queue\Dispatcher\QueueMessageDispatcher.cs:line 38
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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Jason Fauchelle
Raygun
Posted on
Oct 21 2014
Hello,
I will be updating this forum thread when this fix is available. This was originally going to be part of version 4 which will be released soon, but due to the size of version 4, this fix will instead be included in the very next version after v4 which is expected to be available sometime next week.
Will get back to you soon when this is available.
-Jason Fauchelle
Jason Fauchelle
Raygun
Posted on
Nov 03 2014
Hello,
The issue with flagging an exception as sent has been resolved in the latest version of Raygun4Net (4.0.1). This is available in NuGet right now.
I went with both of your suggestions - first check the generic type parameters of the dictionary, and also have a try catch block if anything fails.
-Jason Fauchelle