[DevExpress Support Team: CLONED FROM T242111: NullReferenceException in DevExpress.Utils.Text.FontsCache.GetFontCacheByFont]
I have reverse engineered the applied logic and in all cases there was 1 common factor that is the cause of errors:
- Object reference not set to an instance of an object.
- Object is currently in use elsewhere.
The error is the introduction of "DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)".
This class shares windows fonts between threads and that is STRICTLY FORBIDDEN. Windows usage of GDI resources (during paint message handling but also stuff like "DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, IWordBreakProvider wordBreakProvider, Boolean& isCropped)") is restricted to the thread that has created the GDI resource.
In other words: "Only the thread that has created a font or window may use it, all other threads are not allowed to send windows paint messages to those windows". Measuring the size of a font in a window is also some type of paint action (although invisible because only the size of the painted text is returned).
Solution (only one of both should be implemented): - The class "Text.FontsCache" must add the current-thread-ID to the ID that is used to store the created font in the cache.
- Each thread must make its own instance of the class "Text.FontsCache".
Hello Stephan,
Thank you for pointing out this issue. I have thoroughly reviewed the mentioned method and want to clarify some details. First, however, let me start with some technical background.
The DevExpress.Utils.Text.FontsCache class is declared using an internal modifier. This class can be instantiated only inside the DevExpress.Data assembly. There is only one method where we create a FontsCache instance. It is the DevExpress.Utils.Text.TextUtils.FontsCache static property getter. This method assigns the FontsCache instance to the static field marked with the ThreadStaticAttribute attribute.
This approach guarantees that each thread has its own FontsCache instance and it is not possible to directly obtain a FontsCache instance from another thread. However, errors always happen, so we will greatly appreciate it if you can share more details about how you faced this issue. Have you managed to reproduce the situation when the FontsCache instance contains a reference to a Font instance created in a different thread? Do you have a test project that stably reproduces this error?
I am looking forward to hearing from you.
I currently do not have a project that I may share with you (it would also requires additional capture hardware and licenses that you don't have) but I can share the stack dumps of the different scenarios were it occurs. The error also don't always occurs at the same timing (or sometimes it just works) depending on the timing of which thread was first to create the font.
Maybe the 'ThreadStaticAttribute attribute' is not working (this can be easily tested by looking if the cache returns different memory pointers when requesting the same font from multiple threads. Maybe the obtained font is stored in a variable that is shared between threads.
//////////\
Object reference not set to an instance of an object.
at DevExpress.Utils.AppearanceObject.CalcDefaultTextSize(Graphics g)
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(GraphicsCache cache, String text, Int32 maxWidth)
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(Graphics g, String text, Int32 maxWidth)
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSize(Graphics g, Boolean useDisplayText)
at DevExpress.XtraEditors.ViewInfo.BaseEditViewInfo.CalcBestFitTextSize(Graphics g)
at DevExpress.XtraEditors.ViewInfo.BaseEditViewInfo.CalcBestFit(Graphics g)
at DevExpress.XtraEditors.ViewInfo.TextEditViewInfo.CalcMinHeightCore(Graphics g)
at DevExpress.XtraEditors.BaseEdit.CalcPreferredHeight()
at DevExpress.XtraEditors.BaseEdit.get_PreferredHeight()
at DevExpress.XtraEditors.BaseEdit.LayoutChanged()
at DevExpress.XtraEditors.TextEdit.LayoutChanged(Boolean updateMask)
at DevExpress.XtraEditors.TextEdit.LayoutChanged()
at DevExpress.XtraEditors.BaseEdit.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.TextEdit.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
___
Object reference not set to an instance of an object.
at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)
at DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, IWordBreakProvider wordBreakProvider, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth, Int32 maxHeight, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcDefaultTextSize()
at DevExpress.XtraEditors.LabelControl.CalcIXtraResizableControlMinMaxSize(Boolean calcMin)
at DevExpress.XtraEditors.LabelControl.CalcSizeableMinSize()
at DevExpress.XtraEditors.BaseControl.RaiseSizeableChanged()
at DevExpress.XtraEditors.LabelControl.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at DevExpress.XtraEditors.LabelControl.set_Text(String value)
at Tiveria.TestWizard.Applications.Plugins.Commands.Audio.AudioMeasureControl.<>c__DisplayClass1.<newEngine_SampleHandlerEvent>b__0() in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.Commands.Audio\ui\AudioMeasureControl.cs:line 92
at Tiveria.Common.Extensions.ControlExtensions.ExecuteInUIContextAndAsync(Control ctrl, Action action)
at Tiveria.TestWizard.Applications.Plugins.Commands.Audio.AudioMeasureControl.newEngine_SampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.Commands.Audio\ui\AudioMeasureControl.cs:line 88
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngineAdapter.RaiseSampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngineAdapter.cs:line 92
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.OnSampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 217
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.ProcessOneSample(Double dSampleTime, UInt32 pBuffer, UInt32 nBufferLen) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 137
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.on_process_audio_buffer(Double dSampleTime, UInt32 pBuffer, UInt32 nBufferLen, UInt32 bIsKeyFrame, UInt32 pUserData) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 113
___
Object is currently in use elsewhere.
at System.Drawing.Graphics.get_PageUnit()
at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)
at DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, IWordBreakProvider wordBreakProvider, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth, Int32 maxHeight, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcDefaultTextSize()
at DevExpress.XtraEditors.LabelControl.CalcIXtraResizableControlMinMaxSize(Boolean calcMin)
at DevExpress.XtraEditors.LabelControl.CalcSizeableMinSize()
at DevExpress.XtraEditors.BaseControl.RaiseSizeableChanged()
at DevExpress.XtraEditors.LabelControl.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at DevExpress.XtraEditors.LabelControl.set_Text(String value)
at Tiveria.TestWizard.Applications.Plugins.Commands.Audio.AudioMeasureControl.<>c__DisplayClass1.<newEngine_SampleHandlerEvent>b__0() in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.Commands.Audio\ui\AudioMeasureControl.cs:line 91
at Tiveria.Common.Extensions.ControlExtensions.ExecuteInUIContextAndAsync(Control ctrl, Action action)
at Tiveria.TestWizard.Applications.Plugins.Commands.Audio.AudioMeasureControl.newEngine_SampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.Commands.Audio\ui\AudioMeasureControl.cs:line 88
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngineAdapter.RaiseSampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngineAdapter.cs:line 92
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.OnSampleHandlerEvent(Double SampleTime, IntPtr pBuffer, Int32 BufferLen, Int64 SampleIndex) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 217
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.ProcessOneSample(Double dSampleTime, UInt32 pBuffer, UInt32 nBufferLen) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 137
at Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.on_process_audio_buffer(Double dSampleTime, UInt32 pBuffer, UInt32 nBufferLen, UInt32 bIsKeyFrame, UInt32 pUserData) in c:\build\TestWizzard\SuiteV1.4\Sources\Applications\Plugins\Plugins.HDMICapture\AudioCaptureEngine.cs:line 113
___
Object reference not set to an instance of an object.
at DevExpress.Utils.AppearanceObject.CalcDefaultTextSize(Graphics g)
at DevExpress.Utils.Text.StringPainter.SetFont(StringBlock block, Graphics graphics, Font font)
at DevExpress.Utils.Text.StringPainter.UpdateFont(Graphics graphics, List`1 strings, Font font)
at DevExpress.Utils.Text.StringPainter.Calculate(StringCalculateArgs e)
at DevExpress.XtraBars.Ribbon.ViewInfo.RibbonItemViewInfoCalculator.CalcHtmlStringInfo(Graphics g, RibbonItemViewInfo itemInfo)
at DevExpress.XtraBars.Ribbon.ViewInfo.RibbonItemViewInfoCalculator.CalcLargeButtonViewInfo(Graphics graphics, RibbonItemViewInfo item)
at DevExpress.XtraBars.Ribbon.ViewInfo.RibbonItemViewInfo.CheckViewInfo(Graphics graphics)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonItemPainter.DrawObject(ObjectInfoArgs e)
at DevExpress.Utils.Drawing.ObjectPainter.DrawObject(GraphicsCache cache, ObjectPainter painter, ObjectInfoArgs e)
at DevExpress.Utils.Drawing.Animation.XtraAnimator.DrawAnimationHelper(GraphicsCache cache, ISupportXtraAnimation obj, Object animationId, ObjectPainter painter, ObjectInfoArgs info, ObjectPainter textPainter, ObjectInfoArgs textInfo)
at DevExpress.Utils.Drawing.Animation.XtraAnimator.DrawAnimationHelper(GraphicsCache cache, ISupportXtraAnimation obj, Object animationId, ObjectPainter painter, ObjectInfoArgs info, DrawTextInvoker drawTextMethod, Object textInfo)
at DevExpress.XtraBars.Ribbon.ViewInfo.RibbonItemViewInfoCalculator.DrawItem(GraphicsCache cache, RibbonItemViewInfo itemInfo)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonPanelGroupPainter.DrawItem(RibbonViewInfo viewInfo, GraphicsCache cache, RibbonItemViewInfo itemInfo)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonPanelGroupPainter.DrawItems(ObjectInfoArgs e)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonPanelPainter.DrawGroup(RibbonViewInfo viewInfo, GraphicsCache cache, RibbonPageGroupViewInfo groupInfo)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonPanelPainter.DrawObject(ObjectInfoArgs e)
at DevExpress.Utils.Drawing.ObjectPainter.DrawObject(GraphicsCache cache, ObjectPainter painter, ObjectInfoArgs e)
at DevExpress.XtraBars.Ribbon.Drawing.RibbonPainter.Draw(GraphicsCache cache, RibbonViewInfo viewInfo)
at DevExpress.XtraBars.Ribbon.RibbonControl.RibbonPaint(PaintEventArgs e)
at DevExpress.XtraBars.Ribbon.RibbonControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraBars.Ribbon.RibbonControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
___
(We are using v15.1)
Object reference not set to an instance of an object.
at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)
at DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, IWordBreakProvider wordBreakProvider, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth, Int32 maxHeight, Boolean& isCropped)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcSimpleTextSize(String Text, Boolean useHotkeyPrefix, LabelAutoSizeMode mode, Int32 predWidth, Int32 predHeight)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcTextSize(String Text, Boolean useHotkeyPrefix, LabelAutoSizeMode mode, Int32 predWidth, Int32 predHeight)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcTextSize(String Text, Boolean useHotkeyPrefix, LabelAutoSizeMode mode)
at DevExpress.XtraEditors.LabelControl.CalcIXtraResizableControlMinMaxSize(Boolean calcMin)
at DevExpress.XtraEditors.LabelControl.CalcSizeableMinSize()
at DevExpress.XtraEditors.BaseControl.RaiseSizeableChanged()
at DevExpress.XtraEditors.LabelControl.AdjustSize(Boolean skipCheckHandleCreated)
at DevExpress.XtraEditors.LabelControl.LayoutChanged(Boolean isVisualUpdate)
at DevExpress.XtraEditors.LabelControl.LayoutChanged()
at DevExpress.XtraEditors.LabelControl.OnParentForeColorChanged(EventArgs e)
at System.Windows.Forms.Control.OnForeColorChanged(EventArgs e)
at DevExpress.XtraLayout.LayoutControl.OnForeColorChanged(EventArgs e)
at DevExpress.XtraLayout.LayoutControl.OnForeColorUpdated()
at DevExpress.XtraLayout.LayoutControl.CheckForeColor()
at DevExpress.XtraLayout.LayoutControl.PaintIt(PaintEventArgs e)
at DevExpress.XtraLayout.LayoutControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at DevExpress.XtraLayout.LayoutControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
___
at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)
at DevExpress.XtraEditors.ViewInfo.BaseButtonViewInfo.GetTextAscentHeight()
at DevExpress.XtraEditors.ViewInfo.BaseButtonViewInfo.CalcTextBounds(Graphics gr)
at DevExpress.XtraEditors.ViewInfo.BaseButtonViewInfo.CalcViewInfo(Graphics g)
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.UpdateObjectStateCore()
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.UpdateObjectState(MouseButtons mouseButtons, Point mousePosition)
at DevExpress.XtraEditors.BaseControl.UpdateViewInfoState(Boolean useValidMouse)
at DevExpress.XtraEditors.BaseButton.UpdatePressedState(Boolean setPressed)
at DevExpress.XtraEditors.BaseButton.OnLostFocus(EventArgs e)
at System.Windows.Forms.Control.WmKillFocus(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
___
Do you have any info for me (how to work around this problem). We just acquired 3 ^#$^%$@ licences a week ago and now I am under pressure to revert everything (trow DevExpress WinForms 15.1 out). I have seen that his problem has been reported reported by so many people… please keep me posted on the progress solving this.
What would be the last stable version that does not have this bug?
Hello Stephan,
I have show the information you provided to our R&D team, and they need additional time for research. I will get back to you if they need more details or any new information. Please bear with us. We will do our best to help you resolve this problem.
Want to say I have the exact same problem (using v14.1)
In fact, I've this problem only at 1 customer site. When they run our app, they have the same error. This happen since several months, but as we can't reprod it and it was always on the same line of code I made a quick & dirty fix with a try/catch. The problem is that today after an update it happen again elsewhere.
The code run in an Outlook add-in, and the error is always triggered when Outlook start, so it's on the main thread where all controls are created.
---- Stack Trace ----
DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(graphics As Graphics, font As Font)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
DevExpress.Utils.Text.TextUtils.GetStringSize(g As Graphics, text As String, font As Font, stringFormat As StringFormat, maxWidth As Int32, maxHeight As Int32, wordBreakProvider As IWordBreakProvider, isCropped As Boolean&)
AddinExpress.OL.2005.DLL: N 0007 (0x7) IL
DevExpress.Utils.Text.TextUtils.GetStringSize(g As Graphics, text As String, font As Font, stringFormat As StringFormat, maxWidth As Int32, maxHeight As Int32, isCropped As Boolean&)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(g As Graphics, s As String, font As Font, strFormat As StringFormat, maxWidth As Int32, maxHeight As Int32, isCropped As Boolean&)
AddinExpress.OL.2005.DLL: N 0027 (0x1B) IL
DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(g As Graphics, s As String, font As Font, strFormat As StringFormat, maxWidth As Int32)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcSimpleTextSize(Text As String, useHotkeyPrefix As Boolean, mode As LabelAutoSizeMode, predWidth As Int32, predHeight As Int32)
AddinExpress.OL.2005.DLL: N 0216 (0xD8) IL
DevExpress.XtraEditors.LabelControl.GetPreferredSize(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
System.Windows.Forms.Layout.DefaultLayout.xLayoutDockedControl(element As IArrangedElement, newElementBounds As Rectangle, measureOnly As Boolean, preferredSize As Size&, remainingBounds As Rectangle&)
AddinExpress.OL.2005.DLL: N 0202 (0xCA) IL
System.Windows.Forms.Layout.DefaultLayout.LayoutDockedControls(container As IArrangedElement, measureOnly As Boolean)
AddinExpress.OL.2005.DLL: N 0647 (0x287) IL
System.Windows.Forms.Layout.DefaultLayout.xLayout(container As IArrangedElement, measureOnly As Boolean, preferredSize As Size&)
AddinExpress.OL.2005.DLL: N 0153 (0x99) IL
System.Windows.Forms.Layout.DefaultLayout.GetPreferredSize(container As IArrangedElement, proposedBounds As Size)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
System.Windows.Forms.ContainerControl.GetPreferredSizeCore(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0033 (0x21) IL
System.Windows.Forms.Control.GetPreferredSize(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0090 (0x5A) IL
System.Windows.Forms.Layout.ElementProxy.GetPreferredSize(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
System.Windows.Forms.Layout.FlowLayout.xLayoutRow(containerProxy As ContainerProxy, elementProxy As ElementProxy, startIndex As Int32, endIndex As Int32, rowBounds As Rectangle, breakIndex As Int32&, measureOnly As Boolean)
AddinExpress.OL.2005.DLL: N 0202 (0xCA) IL
System.Windows.Forms.Layout.FlowLayout.xLayout(container As IArrangedElement, displayRect As Rectangle, measureOnly As Boolean)
AddinExpress.OL.2005.DLL: N 0132 (0x84) IL
System.Windows.Forms.Layout.FlowLayout.GetPreferredSize(container As IArrangedElement, proposedConstraints As Size)
AddinExpress.OL.2005.DLL: N 0015 (0xF) IL
System.Windows.Forms.Panel.GetPreferredSizeCore(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0033 (0x21) IL
System.Windows.Forms.Control.GetPreferredSize(proposedSize As Size)
AddinExpress.OL.2005.DLL: N 0090 (0x5A) IL
System.Windows.Forms.Layout.DefaultLayout.LayoutAutoSizedControls(container As IArrangedElement)
AddinExpress.OL.2005.DLL: N 0106 (0x6A) IL
System.Windows.Forms.Layout.DefaultLayout.xLayout(container As IArrangedElement, measureOnly As Boolean, preferredSize As Size&)
AddinExpress.OL.2005.DLL: N 0177 (0xB1) IL
System.Windows.Forms.Layout.DefaultLayout.LayoutCore(container As IArrangedElement, args As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
System.Windows.Forms.Layout.LayoutEngine.Layout(container As Object, layoutEventArgs As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0000 (0x0) IL
System.Windows.Forms.Control.OnLayout(levent As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0047 (0x2F) IL
System.Windows.Forms.ScrollableControl.OnLayout(levent As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0035 (0x23) IL
System.Windows.Forms.Control.PerformLayout(args As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0105 (0x69) IL
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(affectedElement As IArrangedElement, affectedProperty As String)
AddinExpress.OL.2005.DLL: N 0008 (0x8) IL
System.Windows.Forms.Control.PerformLayout(args As LayoutEventArgs)
AddinExpress.OL.2005.DLL: N 0166 (0xA6) IL
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(affectedElement As IArrangedElement, affectedProperty As String)
AddinExpress.OL.2005.DLL: N 0008 (0x8) IL
System.Windows.Forms.ControlCollection.Add(value As Control)
AddinExpress.OL.2005.DLL: N 0301 (0x12D) IL
DF.ApplicationBlocks.ControlsLibrary.Filtering.PanelFilters.buildFilters()
PanelFilters.cs: line 0143, col 17, IL 0330 (0x14A)
DF.ApplicationBlocks.ControlsLibrary.Filtering.PanelFilters.set_AvailableFilters(value As IList`1)
PanelFilters.cs: line 0034, col 17, IL 0008 (0x8)
DF.ApplicationBlocks.ControlsLibrary.Filtering.FilterTextEdit.set_AvailableFilters(value As IList`1)
FilterTextEdit.cs: line 0070, col 17, IL 0001 (0x1)
DF.MailFlow.Presentation.UI.Controls.Search.Search.intiValuesFromController()
Search.cs: line 0094, col 17, IL 0033 (0x21)
DF.MailFlow.Presentation.UI.Controls.Search.Search.set_Controller(value As SearchController)
Search.cs: line 0035, col 17, IL 0024 (0x18)
DF.MailFlow.OutlookPlugin.Controls.ctlDashboard.updateTabActivated(tab As DashboardTabs)
ctlDashboard.cs: line 0389, col 17, IL 0147 (0x93)
DF.MailFlow.OutlookPlugin.Controls.ctlDashboard.load()
ctlDashboard.cs: line 0171, col 21, IL 0194 (0xC2)
DF.MailFlow.OutlookPlugin.Controls.ctlDashboard.ctlDashboard_Load(sender As Object, e As EventArgs)
ctlDashboard.cs: line 0647, col 13, IL 0001 (0x1)
System.Windows.Forms.UserControl.OnLoad(e As EventArgs)
AddinExpress.OL.2005.DLL: N 0025 (0x19) IL
DevExpress.XtraEditors.XtraUserControl.OnLoad(e As EventArgs)
AddinExpress.OL.2005.DLL: N 0049 (0x31) IL
System.Windows.Forms.UserControl.OnCreateControl()
AddinExpress.OL.2005.DLL: N 0006 (0x6) IL
System.Windows.Forms.Control.CreateControl(fIgnoreVisible As Boolean)
AddinExpress.OL.2005.DLL: N 0191 (0xBF) IL
System.Windows.Forms.Control.CreateControl(fIgnoreVisible As Boolean)
AddinExpress.OL.2005.DLL: N 0146 (0x92) IL
System.Windows.Forms.Control.CreateControl()
AddinExpress.OL.2005.DLL: N 0007 (0x7) IL
System.Windows.Forms.Control.SetVisibleCore(value As Boolean)
AddinExpress.OL.2005.DLL: N 0194 (0xC2) IL
System.Windows.Forms.Form.SetVisibleCore(value As Boolean)
AddinExpress.OL.2005.DLL: N 0140 (0x8C) IL
AddinExpress.Extensions.ADXForm.ShowInternalNormal()
AddinExpress.OL.2005.DLL: N 0302 (0x12E) IL
AddinExpress.OL.ADXOlForm.AdxOlShow(appWindowProperty As AppWindowProperty, raiseEvents As Boolean)
AddinExpress.OL.2005.DLL: N 0392 (0x188) IL
AddinExpress.OL.ADXOlFormsManager.DoExplorerFormShow(Item As ADXOlFormsCollectionItem, ExplorerArgs As ADXOlExplorerArguments)
AddinExpress.OL.2005.DLL: N 0505 (0x1F9) IL
Hello,
@Stephan: Both exceptions (NullReferenceException and InvalidOperationException) might have the same root. According to exceptions callstacks, the most probable reason is instantiating several Graphics objects referencing the same window handle in different threads.
This situation can occur when a control created in the UI thread was modified from the background thread, which does not have its own message loop. Two of the callstacks you provided begin from the method executed in the background thread: Tiveria.TestWizard.Applications.Plugins.CaptureEngine.HDMI.AudioCaptureEngine.on_process_audio_buffer.
Another method that is executed later modifies the LabelControl.Text property value: Tiveria.TestWizard.Applications.Plugins.Commands.Audio.AudioMeasureControl.newEngine_SampleHandlerEvent. If this is performed in the background thread, this can be a culprit. To be precise, this method modifies the LabelControl.Text property value using some helper method: Tiveria.Common.Extensions.ControlExtensions.ExecuteInUIContextAndAsync. This method name makes me think that it synchronizes the method execution with the UI thread. However, the callstack indicates that this method continues in the background thread and sets the LabelControl.Text property value.
If my assumption is correct, modify the code and use the Control.BeginInvoke, Control.Invoke methods to delegate executing the code that modifies UI controls to the UI thread. This approach of accessing UI controls from the background thread is recommended by MSDN: How to: Make Thread-Safe Calls to Windows Forms Controls.
@Fabrice: Your callstack is slightly different. To process your case more efficiently, I created a separate ticket on your behalf: T313735: FontsCache GetFontCacheByFont method throws exception. I will reply to you in this ticket soon.
I get almost the same error and callstack.
System.NullReferenceException: Object reference not set to an instance of an object. at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font) at DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, IWordBreakProvider wordBreakProvider, Boolean& isCropped) at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth, Int32 maxHeight, Boolean& isCropped) at DevExpress.Utils.Text.StringPainter.SetupSimpleString(StringInfo info, StringCalculateArgs e) at DevExpress.Utils.Text.StringPainter.Calculate(StringCalculateArgs e) at DevExpress.Utils.Drawing.FooterCellPainter.CalcTextSize(ObjectInfoArgs e) at DevExpress.Utils.Drawing.FooterCellPainter.CalcObjectMinBounds(ObjectInfoArgs e) at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcGroupFooterCellHeight() at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcGroupFooterHeight() at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRectsConstants() at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRects(Rectangle bounds, Boolean partital) at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcCore(Graphics g, Rectangle bounds) at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.Calc(Graphics g, Rectangle bounds) at DevExpress.XtraGrid.Views.Base.ColumnView.DoInternalLayout() at DevExpress.XtraGrid.Views.Base.ColumnView.CalculateLayout() at DevExpress.XtraGrid.Views.Grid.GridView.LayoutChanged() at DevExpress.XtraGrid.Views.Base.BaseView.EndUpdateCore(Boolean synchronized) at DevExpress.XtraGrid.Views.Base.ColumnView.OnDataController_DataSourceChanged(Object sender, EventArgs e) at DevExpress.XtraGrid.Views.Grid.GridView.OnDataController_DataSourceChanged(Object sender, EventArgs e) at DevExpress.Data.DataControllerBase.RaiseListSourceChanged() at DevExpress.Data.DataControllerBase.SetListSourceCore(IList value) at DevExpress.Data.CurrencyDataController.OnDataSourceChanged() at DevExpress.Data.CurrencyDataController.SetDataSource(BindingContext context, Object dataSource, String dataMember) at DevExpress.XtraGrid.Views.Base.BaseView.SetDataSource(BindingContext context, Object dataSource, String dataMember) at DevExpress.XtraGrid.Views.Grid.GridView.SetDataSource(BindingContext context, Object dataSource, String dataMember) at DevExpress.XtraGrid.GridControl.ActivateDataSource() at DevExpress.XtraGrid.GridControl.set_DataSource(Object value) at UserControlList.RefreshData()
And I do use Invoke() in that method.Hello Andreas,
To process your recent post more efficiently, I've created a separate ticket on your behalf: NullReferenceException is thrown in the GetFontCacheByFont method.
I will address it shortly.
Still no Fix ?
Hello Ruud,
We have a couple of tickets with similar call stacks, but we are unable to reproduce these issues on our side, that is why we cannot fix them. I would also like to mention that usually such behavior occurs in multi-threading scenarios, when you access controls from a non-UI thread. If you face a similar issue, I suggest you review the How to: Make Thread-Safe Calls to Windows Forms Controls article. If this information does not help, the best way to proceed is to create a separate ticket in this regard and provide us with a sample where the issue is reproducible. It will help us to find the culprit.