Silverlight Tip: Why do I get “An unhandled exception of type ‘System.OutOfMemoryException’ occurred in Unknown Module.” ?

In the past 4-5 days I have been busy, trying to figure out a VERY strange problem with a PropertyGrid solution we have done in Silverlight. Let me first explain quickly what is the solution about.

This is a PropertyPanel Silverlight control, used to expose the public properties of a bussiness object and allow the user to change them back to the object. Needless to say, the control had to populate these properties via reflection by itself. The tricky part is that we needed to create custom editor controls for each property type.

To make this flexible we added all the property editors as a simple ContentControl and dynamically changed the ControlTemplate of the editor, based on the type of the property.

So far so good. We have implemented the whole mechanism for populating the properties, dynamically creating the ContentControl editors and choosing the ControlTemplate from a list of templates, being predefined.

We have added all those things in a Silverlight Library solution and created another solution (a Silverlight Application, what else ?), where we made a test by passing a custom business object to the control and show it.

Everything went well when we used only the generic build-in controls from the Silverlight SDK for the editors. As soon as I have added a controls from a 3rd Party, or even from System.Windows.Controls, I got the strangest exception on loading:

“An unhandled exception of type ‘System.OutOfMemoryException’ occurred in Unknown Module.”

This was just not enough information. No stack trace, no InnerException, nothing ! I started debugging and pulling out things one by one from the functionality to get to the bottom of the problem. Nothing helped. I spent more than 4 days trying to solve it, but I couldn’t. Finally, while browsing the Google results for the message of the exception, I got to this address:

This is a similar solution by some guys, who faced the same problem. What I have noticed is that they had the problem when the referencing DLLs were broken. As I took a look at our solution I found out that we haven’t referenced the 3rd Party DLLs in the sample solution at all ! I have only referenced them in the Library solution. One might think that this is a normal thing to do, because these DLLs should be exposed to the simple solution by the Library one. Well, one is wrong ! Turned out that Silverlight has some issues on that topic. The exception is totally misleading and if I haven’t found that solution, I wouldn’t had had solved the problem.


  1. Pingback: Twitter / David Justice: RT @JustinAngel: RT (Gd de ...

Leave a Reply

Your email address will not be published. Required fields are marked *