I’ve designed a custom control for a Silverlight website. When I run the debugger, or release it and pull it up over http, the control works perfectly. In the designer view for the control itself, it displays fine as well.
The problem comes when I add the control to the MainPage.xaml app as a control. The designer breaks saying: And Unhandled exception has occurred. System.NullReferenceException
Object reference not set to an instance of an object.
The control pulls its data from a WCF service while it runs its Loaded() event. The WCF service is located on the remote IIS server, not localhost.
I imagine the control is breaking because it can’t pull data from the service in designer-view. Is there any way around this problem? Thanks in advance.
Aside from what @Luke has said, you should actually fix the core of the problem: your data-loading code THROWS when it fails to load. Maybe just handle the error gracefully and CATCH the error and return empty data? Usually this is better for user experience to show nothing (or show a message) than to show a crash.. Your contorl will now crash also in the real release mode – i.e. if the data connection fails.
The IsInDesignTool property is stil very handy: once you fail to load the data, before you return empty set of data, check if the IsInDesignTool is true (as Luke said) – if it is, return an hardcoded example set of data. This way, when the contorl is unable to load and when it detects VisualStudio or Blend it will show some testing data and it will show up as filled with contents in the design view.