Thursday, July 28, 2011

Silverlight - WCF: NotFound Exception

Hi all.

Today I'll try to cover a problem, which many Silverlight developers are facing, trying to make WCF service calls. So the problem is that there are a lot of cases, when the client will get "NotFound" error, and here are the possible reasons for that.
(Make a note, that I will assume that the service is actually running, and you're calling to correct endpoint).
1. The amount of data being transfered is more than the limits - the service and clients are configured for. Remember, even if you haven't manually configured those values, there are some defaults. So this can be a cause for such an exception. Here is a good link as a start point for this case.
2. When a method returs something, which contains, or itself is an Enum type, and you've overriden the default values of that enum, by giving different values to its members, and there is no value with 0, then you'll have the same. This is because during serialization, if you won't assign any value to those members, which are type of the Enum, they will get default value (they are value type), which is 0 for Enums, and the Serializer will try to serialize the 0 to any of the marked values, which don't contain 0, so you'll end up by a Serialization Exception on service side, which won't be handled on client and will come back as a NotFound error.

Good luck with your development.

Thursday, July 7, 2011

Memory Leaks in Silverlight Toolkit

Hi all.
In this post I'll try to share my previous experience about memory leaks I've faced in one of projects I've working on.
The problem was in DateTimPicker control of the Silverlight Toolkit, and also in Accordion. Seems those were not being garbage collected and causing all the stuff related to them even with event handlers to stay there in memory.
So here are few simple tips to follow to avoid such things: Always be sure that you've unregistered any event handlers from the above mentioned controls, because those will make the objects, which in those handlers defined to also stay in memory.
If the controls are defined in a XAML file, just remember to remove it from its parent container. All this is easily handled by a simple interface implemented on a control level (you can call it IReleasable for example), and just call the Release method (defined in this interface) from the Page's unload point. And in this method do this "detach" from the leaking control. Why the unload is not a proper place- because for a control it may fire many times - as the Load event.

Good luck with Silverlight development.