使用 WCF 加载设计时数据时出现 VS2010 设计时错误
先生们。 我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我相信在设计时类中进行 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.