Hello there,
I receive a NullReferenceException at MergeAppearanceProp in random intervalls from different sources. Details like stacktraces and code are at the endd of this post.
I have a grid bound to a UltraBindingSource which is bound to a DataTable (Columns: TimeStamp : DateTime, Type :string, Title : string, Message : string).
In the grid designer, I changed the editor of the message column to an UltraFormattedTextEditor (I have 1 invisible instance in the designer.
The data source is filled with logs. The InitializeRow event checks if not reInitialising and if the Type column equals "ERROR", if so, the backcolour of the row is changed to red.
This works fine for a while (5 - 120 logs/rows). Then a NullReferenceException occurs in Infragistics.Win.AppStyling.AppearanceInfo.MergeAppearanceProp. The top of the Stacktrace differs.Most of the time it happens in the OnPaint event and sometimes in the InitializeRow event (usually in PerformAutoResize)
Am I doing something wrong?
It seems to me, that it is a race condition. Can I somehow avoid it?
If this is a bug, is there a workaround for the meantime? (I just delivered the first demo versions of our software)
Any help is greatly appreciated,
Dennis
private void ultraGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){if (!e.ReInitialize){ Debug.WriteLine("FactoryStatus.InitializeRow " + (iGridRow++).ToString()); if (e.Row.Cells["Type"].Value.ToString().ToUpper().Equals("ERROR")) { e.Row.Appearance.BackColor = Color.Red; }
//Exception usually happens in the next line here e.Row.Cells["TimeStamp"].Column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
e.Row.Cells["Source"].Column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand); e.Row.Cells["Type"].Column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand); e.Row.PerformAutoSize();}}
InitializeRow event stacktrace:
bei Infragistics.Win.AppStyling.AppearanceInfo.MergeAppearanceProp(AppearanceData& appearance, AppearancePropFlags property, Object propertyValue) bei Infragistics.Win.AppStyling.AppearanceInfo.MergeData(AppearanceData& appearance, AppearancePropFlags& requestedProps) bei Infragistics.Win.AppStyling.UIRole.ResolveAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps, RoleState state) bei Infragistics.Win.UltraWinGrid.UltraGridBand.MergeBLOverrideAppearances(AppearanceData& appData, ResolveAppearanceContext& context, OverrideAppearanceIndex index, UIRole role, RoleState roleState) bei Infragistics.Win.UltraWinGrid.UltraGridBand.MergeBLOverrideAppearances(AppearanceData& appData, ResolveAppearanceContext& context, OverrideAppearanceIndex index, RoleState roleState) bei Infragistics.Win.UltraWinGrid.UltraGridRow.ResolveCellAppearance(UltraGridColumn column, AppearanceData& appData, AppearancePropFlags& requestedProps, Boolean cellAppearanceOnly, Boolean forceSelected, ForceActive forceActive, Boolean isMergedCell, Boolean hotTrackingCell, Boolean hotTrackingRow, Boolean isProxyResolution) bei Infragistics.Win.UltraWinGrid.UltraGridLayout.ResolvedCachedCellAppearance(UltraGridRow row, UltraGridColumn column, AppearanceData& appData, AppearancePropFlags& flags, Boolean hotTrackingCell, Boolean hotTrackingRow) bei Infragistics.Win.UltraWinGrid.GridEmbeddableEditorOwnerInfoBase.ResolveAppearance(Object ownerContext, AppearanceData& appearance, AppearancePropFlags& requestedProps, EmbeddableEditorArea area, Boolean hotTracking, String customArea, Boolean isProxyResolution) bei Infragistics.Win.UltraWinGrid.GridEmbeddableEditorOwnerInfoBase.ResolveAppearance(Object ownerContext, AppearanceData& appearance, AppearancePropFlags& requestedProps, EmbeddableEditorArea area, Boolean hotTracking, String customArea) bei Infragistics.Win.EditorWithMask.ResolveAppearance(AppearanceData& appData, AppearancePropFlags& requestedProps, EmbeddableEditorOwnerBase owner, Object ownerContext) bei Infragistics.Win.EditorWithMask.GetSize(EditorSizeInfo& sizeInfo) bei Infragistics.Win.DateTimeEditor.GetSize(EditorSizeInfo& sizeInfo) bei Infragistics.Win.EmbeddableEditorBase.GetSize(EmbeddableEditorOwnerBase owner, Object ownerContext, Boolean valueOnly, Boolean full, Boolean borders, Int32 maxTextWidth, Int32 height) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.CalculateCellTextWidth(UltraGridRow row, Graphics gr, StringFormat stringFormat, Int32 maxColWidth) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.TraverseRowsCallback.Infragistics.Win.UltraWinGrid.IRowCallback.ProcessRow(UltraGridRow row) bei Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(UltraGridBand band, IRowCallback rowCallback, IRowsCollectionCallback rowsCollectionCallback, Boolean recursive, Boolean includeTemplateAddRows) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.CalculateMaxCellTextWidth(Int32 maxColWidth, RowsCollection rows, Int32 nRows, Int32 maxRowsCollections) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResizeHelper(RowsCollection rows, Int32 nRows, Boolean applyWidth, Boolean includeHeader, Boolean includeCells, Int32 maxRowsCollections) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResize(PerformAutoSizeType autoSizeType, Boolean includeHeader) bei Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResize(PerformAutoSizeType autoSizeType) bei De.HfInstruments.HardwarePanels.Controls.FactoryStatus.ultraGrid_InitializeRow(Object sender, InitializeRowEventArgs e) in F:\HardwarePanels\Controls\FactoryStatus.cs:Zeile 178. bei Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeRow(InitializeRowEventArgs e) bei Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) bei Infragistics.Win.UltraWinGrid.UltraGrid.FireInitializeRow(InitializeRowEventArgs e) bei Infragistics.Win.UltraWinGrid.UltraGridRow.FireInitializeRow() bei Infragistics.Win.UltraWinGrid.RowsCollection.OnListChangedHelper(ListChangedEventArgs e, Boolean calledFromBandListChanged) bei Infragistics.Win.UltraWinGrid.RowsCollection.OnListChanged(Object sender, ListChangedEventArgs e)
OnPaint stacktrace:
bei Infragistics.Win.AppStyling.AppearanceInfo.MergeAppearanceProp(AppearanceData& appearance, AppearancePropFlags property, Object propertyValue) bei Infragistics.Win.AppStyling.AppearanceInfo.MergeData(AppearanceData& appearance, AppearancePropFlags& requestedProps) bei Infragistics.Win.AppStyling.UIRole.ResolveAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps, RoleState state) bei Infragistics.Win.UltraWinGrid.UltraGridBand.MergeBLOverrideAppearances(AppearanceData& appData, ResolveAppearanceContext& context, OverrideAppearanceIndex index, UIRole role, RoleState roleState) bei Infragistics.Win.UltraWinGrid.UltraGridBand.MergeBLOverrideAppearances(AppearanceData& appData, ResolveAppearanceContext& context, OverrideAppearanceIndex index, RoleState roleState) bei Infragistics.Win.UltraWinGrid.UltraGridRow.ResolveCellAppearance(UltraGridColumn column, AppearanceData& appData, AppearancePropFlags& requestedProps, Boolean cellAppearanceOnly, Boolean forceSelected, ForceActive forceActive, Boolean isMergedCell, Boolean hotTrackingCell, Boolean hotTrackingRow, Boolean isProxyResolution) bei Infragistics.Win.UltraWinGrid.UltraGridLayout.ResolvedCachedCellAppearance(UltraGridRow row, UltraGridColumn column, AppearanceData& appData, AppearancePropFlags& flags, Boolean hotTrackingCell, Boolean hotTrackingRow) bei Infragistics.Win.UltraWinGrid.CellUIElementBase.InternalInitAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps) bei Infragistics.Win.UltraWinGrid.CellUIElementBase.InitAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps) bei Infragistics.Win.UIElement.InitializeDrawAppearance(AppearanceData& defaultAppearance, AppearanceData& appearance) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) bei Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) bei Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) bei Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) bei Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) bei Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize) bei Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) bei Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) bei Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) bei Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) bei System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) bei System.Windows.Forms.Control.WmPaint(Message& m) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Are you doing anything with threading in your application? I can't really think of anything else that would cause this, and randomly occuring errors, or from different sources each time, are the signature of threading issues. In .NET, you need to make sure that any and all actions that affect the UI will occur on the main UI thread; this includes updating the data source that a grid is bound to.
-Matt
Not the kind of answer I hoped for, but the correct answer ;-) Thanks a lot.
My problem is/was, that the System.Windows.Forms.BindingSource, bound to a DataSet.Table, was updated from a different thread. I have the same cases in different parts of my application. Is there a simple way to solve it, e.g. can the UltraDataSource do it? I did the following, which would be quite some effort to solve for all cases in my software:
LogTable logTable = null;
void OnLoad()
{
logTable = new LogTable();
logBindingSource.DataSource = logTable;
Logger.LogTable.RowChanged += new LogHandler( logAdded );
}
void logAdded(DataTime timestamp, string source, string message, string type)
if(InvokeRequired)
BeginInvoke(new LogHandler(logAdded), timestamp, source, message, type);
else
logTable.AddLogTableRow( timestamp, source, message, type);
Thanks for any advice,
Unfortunately, I'm not aware of any simple solution to the threading issues that can arise; it is also difficult to suggest what to do since I'm not familiar with your application's design. In general, you should abstract your logic for updating the data source into a different structure; if it's easiest for you to load your custom data structure asynchronously, then copy that over to the UltraDataSource by marshalling it to the main thread, that could be one approach. Just using the UltraDataSource doesn't make the method calls thread-safe, though.