We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bug grid writing to System.Console

I get the below when running my app. Basically I have a databound grid control that has a primary key setup for the table. When that constraint is violated in release mode the following exception is thrown, in debug mode it is just written to the console. ************** Exception Text ************** System.TypeInitializationException: The type initializer for "System.Console" threw an exception. ---> System.Runtime.InteropServices.SEHException: External component has thrown an exception. --- End of inner exception stack trace --- at System.Console.WriteLine(String value) at Syncfusion.Diagnostics.TraceUtil.TraceExceptionCatched(Exception e) at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnGridValidating(CancelEventArgs e) at Syncfusion.Windows.Forms.Grid.GridControlBase.OnValidating(CancelEventArgs e) at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnValidating(CancelEventArgs e) at System.Windows.Forms.Control.NotifyValidating() at System.Windows.Forms.ContainerControl.ValidateThroughAncestor(Control ancestorControl) at System.Windows.Forms.ContainerControl.EnterValidation(Control enterControl)

8 Replies

AD Administrator Syncfusion Team June 27, 2005 03:28 PM UTC

Hi Chuck, this is the code in OnGridValidating that handles the exception: protected override void OnGridValidating(CancelEventArgs e) { try { // update data } catch (Exception ex) { TraceUtil.TraceExceptionCatched(ex); if (!ExceptionManager.RaiseExceptionCatched(this, ex)) throw ex; e.Cancel = true; CurrentCell.ErrorMessage = ex.Message; CurrentCell.Exception = ex; this.RaiseValidateFailed(CurrentCell.ColIndex); return; } TraceUtil.TraceExceptionCatched will print the exception to the console window but only in debug builds when the "TRACE" conditional variable is specified. In Release builds that line will be skipped. I don''t understand why writing a string to Console causes an exception. Do you have special security settings? Can you try inserting a line Console.WriteLine("test"); in your app and see if that works? Back to OnGridValidating: After the message was written to the console the method executes if (!ExceptionManager.RaiseExceptionCatched(this, ex)) throw ex; This will check whether you set ExeptionManager.PassThroughExceptions or if you called ExeptionManager.SuspendCatchExceptions. In that case the exception will be rethrown. Did you make any changes to ExeptionManager? After these lines RaiseValidateFailed is called which should display a message box. Do you get that message box? If yes, you can customize or not display the message box by handling the ValidateFailed event and setting e.Handled = true. Stefan >I get the below when running my app. Basically I have a databound grid control that has a primary key setup for the table. When that constraint is violated in release mode the following exception is thrown, in debug mode it is just written to the console. > >************** Exception Text ************** >System.TypeInitializationException: The type initializer for "System.Console" threw an exception. ---> System.Runtime.InteropServices.SEHException: External component has thrown an exception. > --- End of inner exception stack trace --- > at System.Console.WriteLine(String value) > at Syncfusion.Diagnostics.TraceUtil.TraceExceptionCatched(Exception e) > at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnGridValidating(CancelEventArgs e) > at Syncfusion.Windows.Forms.Grid.GridControlBase.OnValidating(CancelEventArgs e) > at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnValidating(CancelEventArgs e) > at System.Windows.Forms.Control.NotifyValidating() > at System.Windows.Forms.ContainerControl.ValidateThroughAncestor(Control ancestorControl) > at System.Windows.Forms.ContainerControl.EnterValidation(Control enterControl) >


AD Administrator Syncfusion Team June 27, 2005 04:32 PM UTC

We do have the TRACE flag set for release builds. Could that be the cause?


AD Administrator Syncfusion Team June 27, 2005 09:02 PM UTC

No, that should not affect the Syncfusion libraries, only TRACE statements in your project. But no matter if TRACE flag is set or not, calling Console.WriteLine or Trace.WriteLine should not throw an exception. Can you check if calling this methods does work in your project? Stefan >We do have the TRACE flag set for release builds. Could that be the cause?


AD Administrator Syncfusion Team June 27, 2005 09:58 PM UTC

It doesn''t seem like the trace or console write is the real problem here. Another example I am finding crashes even in debug mode: Databound grid control bound to a view. The table associated with the view has a primary key (two columns one has fixed value). When you make a selection (dropdown combo) then press the del key to remove the selection I receive the normal pop-up telling me a null value is not allowed then an exception is thrown (below is the output from debug mode): System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) at System.Data.DataRow.SetNewRecord(Int32 record) at System.Data.DataRow.EndEdit() at System.Data.DataRowView.EndEdit() at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.EndEdit() at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() catched at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() in :line 0 System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) at System.Data.DataRow.SetNewRecord(Int32 record) at System.Data.DataRow.EndEdit() at System.Data.DataRow.set_Item(DataColumn column, Object value) at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value) at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) catched at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) in :line 0 System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.ChangeCells(GridRangeInfo range, GridStyleInfo[] cellsInfo, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.Syncfusion.Windows.Forms.Grid.IGridVolatileDataContainer.ChangeCell(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridVolatileData.set_Item(Int32 rowIndex, Int32 colIndex, GridStyleInfo value) at Syncfusion.Windows.Forms.Grid.GridStyleInfoIdentity.OnStyleChanged(StyleInfoBase style, StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.EndUpdate() at Syncfusion.Windows.Forms.Grid.GridCellModelBase.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridComboBoxCellModel.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.ApplyFormattedText(String text) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnSaveChanges() at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.RaiseSaveChanges() at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0 An unhandled exception of type ''System.Data.NoNullAllowedException'' occurred in system.windows.forms.dll Additional information: Column ''uri_id'' does not allow nulls.


AD Administrator Syncfusion Team June 29, 2005 02:22 PM UTC

Chuck, is it possible for you to upload the sample project you are using? That would allow me to debug into it right away. Thanks, Stefan >It doesn''t seem like the trace or console write is the real problem here. Another example I am finding crashes even in debug mode: > >Databound grid control bound to a view. The table associated with the view has a primary key (two columns one has fixed value). When you make a selection (dropdown combo) then press the del key to remove the selection I receive the normal pop-up telling me a null value is not allowed then an exception is thrown (below is the output from debug mode): > >System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. > at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) > at System.Data.DataRow.SetNewRecord(Int32 record) > at System.Data.DataRow.EndEdit() > at System.Data.DataRowView.EndEdit() > at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.EndEdit() > at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() >catched at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() in :line 0 > > System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. > at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) > at System.Data.DataRow.SetNewRecord(Int32 record) > at System.Data.DataRow.EndEdit() > at System.Data.DataRow.set_Item(DataColumn column, Object value) > at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value) > at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value) > at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) >catched at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) in :line 0 > System.Data.NoNullAllowedException: Column ''uri_id'' does not allow nulls. > at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) > at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.SaveCellInfo(GridSaveCellInfoEventArgs e) > at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) > at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType) > at Syncfusion.Windows.Forms.Grid.GridModel.ChangeCells(GridRangeInfo range, GridStyleInfo[] cellsInfo, StyleModifyType modifyType) > at Syncfusion.Windows.Forms.Grid.GridModel.Syncfusion.Windows.Forms.Grid.IGridVolatileDataContainer.ChangeCell(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) > at Syncfusion.Windows.Forms.Grid.GridVolatileData.set_Item(Int32 rowIndex, Int32 colIndex, GridStyleInfo value) > at Syncfusion.Windows.Forms.Grid.GridStyleInfoIdentity.OnStyleChanged(StyleInfoBase style, StyleInfoProperty sip) > at Syncfusion.Styles.StyleInfoBase.OnStyleChanged(StyleInfoProperty sip) > at Syncfusion.Windows.Forms.Grid.GridStyleInfo.OnStyleChanged(StyleInfoProperty sip) > at Syncfusion.Styles.StyleInfoBase.EndUpdate() > at Syncfusion.Windows.Forms.Grid.GridCellModelBase.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) > at Syncfusion.Windows.Forms.Grid.GridComboBoxCellModel.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) > at Syncfusion.Windows.Forms.Grid.GridStyleInfo.ApplyFormattedText(String text) > at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnSaveChanges() > at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.RaiseSaveChanges() > at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) >catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0 >An unhandled exception of type ''System.Data.NoNullAllowedException'' occurred in system.windows.forms.dll > >Additional information: Column ''uri_id'' does not allow nulls.


AD Administrator Syncfusion Team June 30, 2005 07:16 PM UTC

I have opened a direct-trac issue. This happens all over the place including your own databound grid samples any foreign key combobox column if deleted will popup a warning but if you ignore and continue it eventually with throw an exception.


AD Administrator Syncfusion Team June 30, 2005 08:35 PM UTC

Chuck, I got the sample. Thanks for reporting this. This is a bug in the GridDataBoundGrid.OnValidating method. We will get that fixed. If you have source code you can replace this method in GridDataBoundGrid.cs /// protected override void OnValidating(CancelEventArgs e) { base.OnValidating (e); if (!e.Cancel) { // Fixes issues with new records and related tables in MasterDetails scenario CurrentCell.EndEdit(); e.Cancel |= CurrentCell.IsModified; if (binder != null && binder.listManager != null) binder.listManager.Refresh(); } } In the current code base the check for if (!e.Cancel) is missing. If changing source code not an option we found that the following code works around the problem in the mentioned sample: GridDataBoundGrid grid = null; private void gridDataBoundGrid1_ValidateFailed(object sender, GridValidateFailedEventArgs e) { grid = (GridDataBoundGrid) sender; grid.CurrentCell.Lock(); grid.GotFocus += new EventHandler(grid_GotFocus); } private void t_Tick(object sender, EventArgs e) { if (grid != null) grid.CurrentCell.Unlock(); Timer t = (Timer) sender; t.Dispose(); grid = null; } private void grid_GotFocus(object sender, EventArgs e) { if (grid != null) { grid.GotFocus -= new EventHandler(grid_GotFocus); Timer t = new Timer(); t.Tick += new EventHandler(t_Tick); t.Interval = 10; t.Start(); } } We’ll also prepare a private patch with this fix. Then the workaround is not needed anymore. Stefan


AD Administrator Syncfusion Team June 30, 2005 08:45 PM UTC

Thanks for the quick reply. I am currently on a patched release (3.2.1.1) which did not come with source code. The workaround would be too much since we use similar grids in dozens of places some of which are already subclassed. Please let me know when a patch is available, thanks!

Loader.
Live Chat Icon For mobile
Up arrow icon