I've got a DataTable bound to a WPF (.NET 3.5, WPFToolkit.dll) DataGrid. This is inside a very large client-server application. The server can asynchronously send data to the client "engine"; this data is sent in the form of properties which are set onto my control by the engine.
So, as an example of what I mean, I have a class MyFunkyDataGrid : DataGrid. MyFunkyDataGrid has a DependencyProperty called MyFunkyData which is of type Dictionary<string, Object>. Whenever MyFunkyData is changed on the server, it is immediately synchronized on the client, and set onto MyFunkyDataGrid. When MyFunkyData changes, I rip through the dictionary and set the data onto my grid's DataTable.
Of course, when this happens, I first need to clear the DataTable of its current data. So I call dataTable.Clear(). Normally this works a treat. BUT if I am currently editing a cell in MyFunkyDataGrid when the dataTable is cleared I get:
System.ExecutionEngineException was unhandled
Message=Exception of type 'System.ExecutionEngineException' was thrown.
InnerException:
which crashes my app. I've tried calling CancelEdit() on MyFunkyDataGrid, I've tried calling it on the DataRow itself. I've tried calling RejectChanges() on the DataTable before I call Clear(). No dice.
Has anyone ever seen something like this before?