VS2010 Design-Time error when using WCF to load design-time data

452 Views Asked by At

gentlemens. I have following definition in the Silverlight project, MainPage.xaml:

<UserControl
xmlns:model="clr-namespace:Engine.Silverlight.Web.Views;assembly=Engine.Login.Model"
d:DataContext="{d:DesignInstance Type=model:DesignTimeModel, IsDesignTimeCreatable=True}">...

And class in the Engine.Login.Model project, which used for design-time data binding (everything works fine for pre-initialized properties, but):

    public class DesignTimeModel : INotifyPropertyChanged
{
    public DesignTimeModel()
    {
        var d = Deployment.Current.Dispatcher;
        d.BeginInvoke(
            () =>
            {
                CacheClient c = new CacheClient();
                c.GetResourcesCompleted +=(s,e)=>
                    {
                        d.BeginInvoke(
                            () => this.Resources = e.Result);
                    };
                c.GetResourcesAsync();
            }
        );

Unfortunately, I got a System.ObjectDisposedException after WCF request completed (I tried to debug using different instance of VS by attaching to 1st VS instance process, but it does not help - same error, no additional info):

System.ObjectDisposedException
Cannot access a disposed object.
Object name: 'Dispatcher'.
   at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)

I assume the Dispatcher behavior different in the design mode. Can you help me how to resolve the problem to get design-time data using WCF in VS2010 XAML designer?

1

There are 1 best solutions below

2
On

First, I belive that making a WCF call in a design time class isn't really a best practice! You should instead put some static dummy data.

For your problem, try using Deployment.Current.Dispatcher directly instead of pointing a variable to it.