Friday, 2 May 2008

Silverlight 2 - Configuration Files are not picked up

I just saw this post on Mike Taulty's blog about the MaxMessageReceivedSize config setting not working in Silverlight 2's config file.

Mike's solution was to set the property in code but he wasn't sure why he had to do this.

This is happening because the config file is actually never read by Silverlight. It's generated when you add the Service Reference, but it's never picked up. I don't know why it's created actually, it only serves to confuse people! Maybe it will work in a future version... but if you look in the generated Reference.cs of the ImageServiceClient, you will see that the default constructor of the proxy sets the binding to BasicHttpBinding and sets the appropriate Url, essentially mirroring what is in the config file.

Silverlight currently does not have any support for configuration files (there is no System.Configuration namespace at all!). If you wish to configure your Silverlight components, I could suggest that you just use XAML... alternatively you could pass XML through a hidden form field which the Silverlight application reads. The point is that whatever you do will be completely custom.

Anyway I hope this helps someone out there who is wondering why his config changes aren't working.

No comments: