Windows Phone 7 Design Time and Asynch Initialization

I am working on a Windows Phone 7 app and I ran into an interesting problem.  The architecture of the app is MVVM and the ViewModel is a ‘Threat’.  When consuming the ThreatViewModel in my Vi,ew I havew the following code:


This fails because the TheatViewModel created a proxy to consume a WCF service. I made the WCF-creating method, made it public, and called it during the initialization of the page:

public CurrentStatusView() { InitializeComponent(); ThreatViewModel threatViewModel = (ThreatViewModel)this.DataContext; threatViewModel.InitializeLocations(); }

The problem is that consuming the control – the initialize component gets called and this is the error message:


Since initialize component is getting called in deign time, the asynch is getting kicked off – and the designer is throwing an exception.  Rob Seder seems to think it is a .config issue – because the .config is not present in design time, the proxy doesn’t have the information to make the proxy call.

Stepping back, the proxy and asynch call needs to happen outside of the designer – at some point in the code behind to respond to an event on the screen. Perhaps application load or page load.  In any event, merging asycnh calls is not a good idea…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: