使用 WCF 加载设计时数据时出现 VS2010 设计时错误

发布于 2024-11-02 05:27:21 字数 1377 浏览 0 评论 0原文

先生们。 我在 Silverlight 项目 MainPage.xaml 中有以下定义:

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

以及 Engine.Login.Model 项目中的类,用于设计时数据绑定(预初始化属性一切正常,但是):

    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();
            }
        );

不幸的是,我得到了一个WCF 请求完成后出现 System.ObjectDisposeException (我尝试通过附加到第一个 VS 实例进程来使用不同的 VS 实例进行调试,但它没有帮助 - 相同的错误,没有附加信息):

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)

我假设调度程序的行为不同设计模式。 您能帮我解决如何在 VS2010 XAML 设计器中使用 WCF 获取设计时数据的问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-11-09 05:27:21

首先,我相信在设计时类中进行 WCF 调用并不是真正的最佳实践!您应该放置一些静态虚拟数据。

对于您的问题,请尝试直接使用 Deployment.Current.Dispatcher 而不是将变量指向它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文