目前,我完全感到困惑的问题,我有。我写插在另一个应用程序,提供一个公开的。净API。我已经创建了一个类命名的 Room 和我使用一个PropertyGrid允许用户查看和编辑性质的 Room 实例。一些属性被限制在一定的标准值。因此,我使用的定义与TypeDescriptors GetStandardValues() 复盖得到的财产的网格,显示出下降为那些属性。

这是所有工作只是罚款。我正在降落,而且我可以编辑数值没有问题。但现在由于某些原因当我选择 Room PropertyGrid表示的特性的种类型描述为一个黑盒子。

alt text

如果我点击框事实证明白我得到一个闪烁的光标,但我不能什么。如果我然后选择另一个房间我的程序的崩溃,以下例外:

System.InvalidCastException was caught
  Message=Unable to cast object of type 'DVAMC.Room' to type 'DVAMC.Room'.
  Source=DVAMC
  StackTrace:
       at DVAMC.BuildingTypeConverter.GetStandardValuesSupported(ITypeDescriptorContext context) in C:\Documents and Settings\eric.anastas\My Documents\_SVN WC\DVAMC Working\BuildingTypeConverter.cs:line 14
       at System.Windows.Forms.PropertyGridInternal.GridEntry.get_Flags()
       at System.Windows.Forms.PropertyGridInternal.GridEntry.get_NeedsDropDownButton()
       at System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.get_NeedsDropDownButton()
       at System.Windows.Forms.PropertyGridInternal.PropertyGridView.SelectRow(Int32 row)
       at System.Windows.Forms.PropertyGridInternal.PropertyGridView.SelectGridEntry(GridEntry gridEntry, Boolean fPageIn)
       at System.Windows.Forms.PropertyGridInternal.PropertyGridView.GridPositionData.Restore(PropertyGridView gridView)
       at System.Windows.Forms.PropertyGridInternal.PropertyGridView.Refresh(Boolean fullRefresh, Int32 rowStart, Int32 rowEnd)
       at System.Windows.Forms.PropertyGridInternal.PropertyGridView.Refresh()
       at System.Windows.Forms.PropertyGrid.Refresh(Boolean clearCached)
       at System.Windows.Forms.PropertyGrid.set_SelectedObjects(Object[] value)
       at System.Windows.Forms.PropertyGrid.set_SelectedObject(Object value)
       at DVAMC.RoomDetailsForm.set_RoomDetailsSelectedRoom(Room value) in C:\Documents and Settings\eric.anastas\My Documents\_SVN WC\DVAMC Working\RoomDetailsForm.cs:line 115
       at DVAMC.RoomDetailsForm.roomListTreeView_SelectionChanged(Object sender, EventArgs e) in C:\Documents and Settings\eric.anastas\My Documents\_SVN WC\DVAMC Working\RoomDetailsForm.cs:line 159
       at BrightIdeasSoftware.ObjectListView.OnSelectionChanged(EventArgs e)
       at BrightIdeasSoftware.ObjectListView.HandleApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.Form.ShowDialog()
       at DVAMC.RoomDetailsCmd.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in C:\Documents and Settings\eric.anastas\My Documents\_SVN WC\DVAMC Working\RoomDetailsCmd.cs:line 44
  InnerException: 

最后一个项目的堆跟踪点我BuildingTypeConverter.GetStandardValuesSupported()方法,它是表示如下。

GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context)
{
    Room r = (Room)context.Instance; //this is line 14 referenced by the InvalidCastException's stack trace

    if (r.IsLinked)
    {
        return true;
    }
    else
    {
        return false;
    }
}

现在,如果我设定一个断点在线14段,并试图调试该试器不会破坏在断点。此外,如果我补充任意代码之前投堆跟踪从InvalidCastException似乎总是参照第一线的GetStandardValues()无论它是什么。例如我试图如下。

public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context)
    {
        string s = "hello world";   //FIRST LINE
        int i = 0;


        Room r = (Room)context.Instance; 

        .....

我还是得到了同样的InvalidCastException.然而,这是堆叠跟踪参考的第一线上,我的初始化 string s.此外,如果我试图设置一个断点上的这个第一线,它也没有触发的。

就像我之前说这个 工作只是现一天或以前。我甚至试图返回到以前的修订版在我SVN库。我已经走了,早在第一次修订是我创造的定型描述符类,但仍然碰到的问题 InvalidCastExceptions.没有任何人有任何想法什么?

有帮助吗?

解决方案

如果堆跟踪总是显示了相同的线,即使你已经改变了代码,将指示我的ProperyGrid是不运行的相同版本的组件。这进一步证实当你说你把一个断点,但断点是从来没有击中。如果你是内运行调试器Visual Studio我建议你看看输出窗口(按Ctrl+W,O)中,将列的所有大会(与他们的道路),被装载在运行。我已经看到大会版本的混乱,特别是当大会在咨询委员会在那里坚持要求载入一个旧版的组件。

其他提示

这可能是两种类型实际上是不同的,例如如果他们中的一个是从另一个版本的一些组件比其他类型。我不是很确定如果这能发生在你的情况,但它可能是一个问题。

最简单的方式来检查这是对放断点的地方,唯一的例外是抛出。然后你可以看到两种类型在手表或立即窗口看看 o1.GetType().Assembly. FullName (和同样对于其他对象)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top