Friday, October 23, 2009

How to fix "Value does not fall within the expected range" error in Silverlight

The Problem: Your code goes about it's merry way, adding children to parents and so forth when you get the error
Value does not fall within the expected range
The Cause: The problem is caused by two objects having the same name in the same parent. If your canvas has two StackPanels named "spOverlap" then this error is thrown. Why the error message couldn't just say "Duplicate Name Error" no one knows. I've encountered this error when dynamically adding controls to the application.

The Solution (Part 1): The simple way to fix it is to simply name the newly added control with a guid or a ID number of some sort.

The Cause (Part 2): I did in fact do that, and then encountered another error, namely that things were expanding exponentially.

Here's the situation. I have a main control (call it StronScreen), which will spawn a child control (call it StronTab), which has an event (call it StronEntityAdd) that will add a control (call it StronEntity) to StronScreen. I was adding the event to StronTab every time I spawned it, which meant that there were multiple events attached to StronTab as the user went through the application. It worked fine the first time, by which I mean that it added a single instance of StronEntity to StronScreen. The next time I spawned StronTab (this is a necessary and desirable feature of the application) and call StronEntityAdd TWO instances of StronEntity would be added to StronScreen.

The Solution (Part 2): Create the event handler as null when the page is loaded, and when StronTab is called, check to see if the event is null, and if it is, add it to StronTab. If the event handler is not null, then simply don't add it.

A hard problem to diagnose, and the application does have to work that way, but that fixes it.

Labels: ,

How to solve Unhandled Error in Silverlight Application Code: 2104

I've found that I get this error every time I upload a Silverlight application to a new webserver. IIS does not have the correct settings by default.

The Problem: You ftp a Silverlight App to an IIS website, go to the website in a browser, and get the following error:
Message: Unhandled Error in Silverlight Application
Code: 2104
Category: InitializeError
Message: Could not download the Silverlight application. Check web server settings
The Cause: The Silverlight Mime types (.xaml, .xap and .xbap) are not listed in that websites registered mime types, therefore IIS will not send those files to the browser.

The Solution: Open IIS on the server, go to HTTP headers, click on Mime Types, click "Add New" and add the following:

Extension - Mime Type
.xaml - application/xaml+xml
.xap - application/x-silverlight-app
.xbap - application/x-ms-xbap

Hit Apply and your application will load!

Labels: , , ,

Monday, September 14, 2009

Silverlight Data validation problems

So - I spent today making one last ditch effort to get the built-in Silverlight data validation to work in my project, all to no avail. I even posted a question on Stack Overflow, and have yet to receive an answer, which is a first for me. I downloaded several of the samples, from Wildermuth, Liberty and others, and they none of them would work out of the box, they all either had strange dependencies or would throw errors on build. I finally gave up and did the validation manually, the most recent version is on the site now. Granted, I'm trying to do remote data objects, so my situation and the examples are a bit different, but it would be nice to have some degree of success with this.

Labels: ,

Thursday, August 20, 2009

Atlanta

I, along with many others apparently, will be waking up incredibly early on Saturday and trekking up to Alpharetta for the Atlanta Silverlight Firestarter. I haven't been to that many of these events, mostly due to location, but I've heard great things about Firestarters. I'll keep everyone posted.

Note - this is cross posted to my other work site at Digital Tool Factory.

Labels: ,

Tuesday, August 11, 2009

Silverlight Dataform successfully shed

I just uploaded another build of Stronico to the Beta site - I got rid of the dataform method of entering and editing email addresses and phone numbers. Addresses are next!

Labels: , ,

Sunday, September 21, 2008

More updates

I wrote a modal popup - it occurs when one tries to delete a contact that has subsidiary contacts.

Labels:

Thursday, September 18, 2008

First Post!

A test post to see if I've set up the blog correctly. The design is temporary - this will be the blog site for Stronico Contact Management Inc - the world's first SilverLight contact management web app.

Labels: