Menu ▾ ▴

#143 InvalidCastException when editing a cell

C#_v2.7
wont-fix
7
2018-08-27
2015-03-19
bluish5
No

I have an OLV and I create its OLVColumns at runtime. The first has checkboxes, while the second is the only one that is editable.
I'm experiencing this issue: I edit a cell, when I terminate I get InvalidCastException (not handled) and from now on I get the same exception every time I start or end editing a cell.

Exception details:

System.InvalidCastException: Cast specificato non valido.
   in System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
   in System.Windows.Forms.StringSource..ctor(String[] strings)
   in System.Windows.Forms.TextBox.SetAutoComplete(Boolean reset)
   in System.Windows.Forms.TextBox.OnHandleCreated(EventArgs e)
   in System.Windows.Forms.Control.WmCreate(Message& m)
   in System.Windows.Forms.Control.WndProc(Message& m)
   in System.Windows.Forms.TextBoxBase.WndProc(Message& m)
   in System.Windows.Forms.TextBox.WndProc(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I can post the list of loaded assemblies if needed.
Thanks

1 Attachments

Discussion

  • bluish5

    bluish5 - 2015-03-19

    Another screenshot, with the error.

     
  • Phillip Piper

    Phillip Piper - 2015-03-22

    I haven't seen this error before.

    After looking around a bit, I found this thread which (towards the end) suggests that the CoCreateInstance fails because of some sort of threading problem.

    I've looked at the code in OLV that handles the auto completion, and there doesn't seem to be any multi-threading involved.

    Do you do anything that might be using multi-threading?

    Does the problem happen reliably?

    Can you post a full sample code that shows the problem?

     
  • Phillip Piper

    Phillip Piper - 2015-04-07

    I'm glad you found a work around. I have no idea how to actually fix the issue.

    From the looks of all the other messages, it seems that this issue actually has nothing to do with OLV.

     
  • Phillip Piper

    Phillip Piper - 2015-04-07
    • status: open --> wont-fix
     
  • Norbert Vorstädt

    Hello Phillip!

    I have a similar problem. Also getting a InvalidCastException when clicking an editable column. The exception happens at this part of code in StartCellEdit:

            // The event handler may have completely changed the control, so we need to remember it
            this.cellEditor = this.CellEditEventArgs.Control;
    
            this.Invalidate();
            --- this line---> this.Controls.Add(this.cellEditor);
            this.ConfigureControl();
    

    If I pause at the line with the debugger and then continue, the code seems mysteriously to work. So it must have something to do with multithreading. I have checked in the debugger that the control is correctly created (just a simple TextBox).
    As **work-around ** I disabled auto-completion on that column and everything works fine! So, I assume that the auto-completion feature is somehow involved.
    Perhaps this description gives you a hint how to debug the problem. I am working in a tiny demo project, which I could send you to reproduce the problem.

     

Log in to post a comment.