System.EventHandler转换错误

时间:2011-03-02 12:15:20

标签: c# winforms

我有一个Info类,它有以下事件。

    public delegate void GroupNameChangedHandler(string groupName);
    [field: NonSerialized]
    public event GroupNameChangedHandler GroupNameChanged;

另一个类已注册到该事件。它似乎工作正常,但昨天我们的一个客户提到应用程序抛出一些异常,以下是该错误的堆栈跟踪。我不确定客户端的机器或应用程序有什么问题。这适用于近50个其他用户。

Object of type 'System.EventHandler' cannot be converted to type 'EZOMS.OrderEntry.PairsOrderInfo+GroupNameChangedHandler'. (mscorlib)


 Program Location:

   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.ComponentModel.ReflectEventDescriptor.RemoveEventHandler(Object component, Delegate value)
   at System.ComponentModel.ReflectPropertyDescriptor.RemoveValueChanged(Object component, EventHandler handler)
   at System.Windows.Forms.BindingSource.UnwirePropertyChangedEvents(Object item)
   at System.Windows.Forms.BindingSource.Clear()
   at EZOMS.OrderEntry.PairsOrderEntryForm.LoadPairsOrderInfo(PairsOrderInfo pairsOrderInfo) in C:\dev\BRANCH\EZOMS\OrderEntry\PairsOrderEntryForm.cs:line 1063
   at EZOMS.OrderEntry.PairsOrderEntryForm.buttonSave_Click(Object sender, EventArgs e) in C:\dev\BRANCH\EZOMS\OrderEntry\PairsOrderEntryForm.cs:line 765
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

1 个答案:

答案 0 :(得分:0)

听起来你有一个叫GroupName的属性;更改处理程序遵循event EventHandler *Changed模式的约定,因此绑定代码(在属性描述符中,主要是) spot 此模式并尝试使用事件处理程序进行订阅。在这种情况下,它是相当注定的。

可能想要检查他们是否使用相同的.NET版本(包括服务包);也许这在以后的版本中有所改进。

当然,假设 一个GroupName属性,您可以切换回EventHandler并从那里进行订阅者查询。