1

In my Silverlight 5 app, I'm getting an ArgumentNullException with no useful stacktrace. I simply see:

System.ArgumentNullException occurred
Message=Value cannot be null.
Parameter name: key
StackTrace:
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Windows.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj, System.IntPtr unmanagedObjArgs, int argsTypeIndex, int actualArgsTypeIndex, string eventName, uint flags) + 0x31b bytes   

Try as I might, I can't find any uncaught exception to catch! I've disabled Just My Code, I have the debugger set to Break on Thrown for all exceptions, and I've looked for anywhere in my code where this might be happening. I just can't find any way to figure out where it's coming from. It must be a background Silverlight thread applying resources, or otherwise doing something automatically, but I can't figure out what.

The specific scenario is of creating controls through XAML or through code. Through XAML they work fine. When I create them through code I get this mysterious exception.

Help!

Arian Kulp
  • 831
  • 8
  • 31
  • Do you have any calls to Dictionary.FindEntry in your code? – Peter Ritchie May 10 '12 at 03:32
  • No direct calls to FindEntry in any of my code. That's why I wondered if it was something done by the XAML engine behind the scenes. – Arian Kulp May 10 '12 at 05:33
  • The only thing I can think of is that you've subscribed to an event with a null somehow... – Peter Ritchie May 10 '12 at 15:28
  • I gave up and restructured things. I got rid of the error without really understanding how. Thanks for the suggestions though people! – Arian Kulp May 14 '12 at 23:40
  • Hi Arian, It would of great help if you can tell me what is the Restructuring that you did.. Even I am facing the same issue and there is no cluse as to what could be wrong.. This happening on opening new dialog for me.. – CHash11 Mar 26 '13 at 15:24
  • Sorry, Harshal. I can't remember which app I was working on at this point! Is this a phone or web SL app? – Arian Kulp Mar 27 '13 at 04:11

2 Answers2

1

I faced the same isssue and I figured out the exact reason of failure in my case. We are using the Telerik RadRichTextBoxRibbonUI control and there someone has asssigned value {x:Null} to the ApplicationName property in XAML. When I replaced the {x:Null} with a string value the problem was resolved.

Gabe
  • 84,912
  • 12
  • 139
  • 238
CHash11
  • 746
  • 4
  • 14
  • 31
-1

Use a lock on your dictionary to ensure only one thread is accessing it at any given time. This exception can occur when multiple threads access the same Dictionary and corrupt it, causing the internal structure to have null entries in the buckets.

How is this Dictionary<TKey, TValue> exception possible?

Community
  • 1
  • 1
Gabe Halsmer
  • 808
  • 1
  • 9
  • 18