C# System.Runtime.Remoting.RemotingException[4484]设计器进程意外终止?
我创建了一个类来监视属性的更改并触发INotifyPropertyChanged事件 但是,当一个类使用它添加到WPF控件时,设计器会崩溃,并出现未处理的异常 System.Runtime.Remoting.RemotingException[4484]设计器进程 意外终止 有人知道为什么吗C# System.Runtime.Remoting.RemotingException[4484]设计器进程意外终止?,c#,wpf,visual-studio-2012,C#,Wpf,Visual Studio 2012,我创建了一个类来监视属性的更改并触发INotifyPropertyChanged事件 但是,当一个类使用它添加到WPF控件时,设计器会崩溃,并出现未处理的异常 System.Runtime.Remoting.RemotingException[4484]设计器进程 意外终止 有人知道为什么吗 public interface IObservableValue<T>:INotifyPropertyChanged, INotifyPropertyChanging { T Valu
public interface IObservableValue<T>:INotifyPropertyChanged, INotifyPropertyChanging
{
T Value { get; }
}
public class ObservableProperty<T> : IObservableValue<T>
{
public static implicit operator T(ObservableProperty<T> obj)
{
return obj.Value;
}
public ObservableProperty()
:this(default(T))
{
}
public ObservableProperty(T value)
{
val = value;
CheckInterface(val, true);
}
T val;
public T Value
{
get { return val; }
set
{
if (!val.Equals(value))
{
OnPropertyChanging(changingArgs);
CheckInterface( val, false);
val = value;
CheckInterface( val, true);
OnPropertyChanged(changedArgs);
}
}
}
public bool HasValue
{
get { return val!=null; }
}
protected void CheckInterface<TValue>(TValue value, bool add)
{
INotifyPropertyChanging inc = value as INotifyPropertyChanging;
if (inc != null)
{
if (add)
inc.PropertyChanging += new PropertyChangingEventHandler(val_PropertyChanging);
else
inc.PropertyChanging -= new PropertyChangingEventHandler(val_PropertyChanging);
}
INotifyPropertyChanged inpc = value as INotifyPropertyChanged;
if (inpc != null)
{
if (add)
inpc.PropertyChanged += new PropertyChangedEventHandler(val_PropertyChanged);
else
inpc.PropertyChanged -= new PropertyChangedEventHandler(val_PropertyChanged);
}
INotifyCollectionChanged incc = value as INotifyCollectionChanged;
if (incc != null)
{
if (add)
incc.CollectionChanged += new NotifyCollectionChangedEventHandler(val_CollectionChanged);
else
incc.CollectionChanged -= new NotifyCollectionChangedEventHandler(val_CollectionChanged);
}
}
void val_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(changedArgs);
}
void val_PropertyChanging(object sender, PropertyChangingEventArgs e)
{
OnPropertyChanging(changingArgs);
}
void val_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(changedArgs);
}
void OnPropertyChanged(PropertyChangedEventArgs changed)
{
var handler = PropertyChanged;
if (handler != null) handler(this, changed);
}
void OnPropertyChanging(PropertyChangingEventArgs changed)
{
var handler = PropertyChanging;
if (handler != null) handler(this, changed);
}
private static PropertyChangedEventArgs changedArgs = new PropertyChangedEventArgs("Value");
private static PropertyChangingEventArgs changingArgs = new PropertyChangingEventArgs("Value");
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
}
公共接口IObservableValue:INotifyPropertyChanged,INotifyPropertyChanged
{
T值{get;}
}
公共类ObservableProperty:IObservableValue
{
公共静态隐式运算符T(ObservableProperty obj)
{
返回对象值;
}
公共财产
:此(默认值(T))
{
}
公共可观测属性(T值)
{
val=值;
检查接口(val,true);
}
T值;
公共价值
{
获取{return val;}
设置
{
如果(!val.Equals(value))
{
房地产交易(changingArgs);
检查接口(val,false);
val=值;
检查接口(val,true);
不动产变更(变更号);
}
}
}
公共布尔值
{
获取{return val!=null;}
}
受保护的无效检查接口(TValue、bool add)
{
INotifyPropertyChanging inc=作为INotifyPropertyChanging的值;
如果(inc!=null)
{
如果(添加)
inc.PropertyChanging+=新的PropertyChangingEventHandler(val_PropertyChanging);
其他的
inc.PropertyChanging-=新的PropertyChangingEventHandler(val_PropertyChanging);
}
INotifyPropertyChanged inpc=作为INotifyPropertyChanged的值;
如果(inpc!=null)
{
如果(添加)
inpc.PropertyChanged+=新的PROPERTYCHANGEDVENTHANDLER(val_PropertyChanged);
其他的
inpc.PropertyChanged-=新的PROPERTYCHANGEDVENTHANDLER(val_PropertyChanged);
}
INotifyCollectionChanged incc=作为INotifyCollectionChanged的值;
如果(incc!=null)
{
如果(添加)
incc.CollectionChanged+=新通知collectionchangedventhandler(val\u CollectionChanged);
其他的
incc.CollectionChanged-=新通知collectionchangedventhandler(val\u CollectionChanged);
}
}
void val_CollectionChanged(对象发送方,NotifyCollectionChangedEventArgs e)
{
不动产变更(变更号);
}
void val_PropertyChanging(对象发送方,PropertyChangingEventArgs e)
{
房地产交易(changingArgs);
}
void val_PropertyChanged(对象发送方,PropertyChangedEventArgs e)
{
不动产变更(变更号);
}
无效OnPropertyChanged(PropertyChangedEventArgs已更改)
{
var handler=PropertyChanged;
if(handler!=null)handler(this,changed);
}
在PropertyChange上无效(PropertyChangingEventArgs已更改)
{
var handler=PropertyChanging;
if(handler!=null)handler(this,changed);
}
私有静态属性changedeventargs changedArgs=新属性changedeventargs(“值”);
私有静态属性ChangingEventArgs changingArgs=新属性ChangingEventArgs(“值”);
公共事件属性更改事件处理程序属性更改;
公共事件属性更改EventHandler属性更改;
}
我唯一看到的是这一行
if(!val.Equals(value))
当
val
为null时,将抛出NullReferenceException
。另外,我打赌设计器使用类的默认构造函数,这意味着val
在设计器中为null,因此值设置程序会引发异常。非常奇怪,但重新启动VS2012修复了它,因此不应在泛型上下文中使用它。而是使用equalabilitycomparer.Default.Compare
.Compare。该类中不存在Compare,你是说equals吗?但是这不是问题,因为要触发该代码,它必须绑定到Value属性的setter,默认构造函数直接设置属性,而不使用属性逻辑,这是在将对象添加到控件资源字典的时候。同样在这个实例中,泛型类型是double,所以null不是一个可能的值。由于关闭VS2012的每一个打开的副本似乎已经治愈了它,我认为这一定是设计者的一种特殊现象。这是否回答了您的问题?