[DevExpress Support Team: CLONED FROM T509071: NullReferenceException is thrown in the GetFontCacheByFont method]
Is there any update on this issue? I am getting it too
Type:
System.NullReferenceException
Message:
Object reference not set to an instance of an object.
StackTrace:
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.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth, Int32 maxHeight, 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()
Hello Steven,
I am afraid the provided information is not sufficient to determine the cause of the issue. Nevertheless, such errors can occur in multi-threading scenarios when a background thread changes the control's state or modifies its properties while the UI thread performs some operations against this control. Please make sure that the code executed in the background thread accesses UI controls correctly using either of the approaches described in the How to: Make Thread-Safe Calls to Windows Forms Controls document.
Also, please clarify what version of our components you are using in your application. In addition, would you please clarify if it is necessary to preform special steps to reproduce it? If so, describe them.
It would be great if you provide a project to illustrate this issue.
I look forward to your response.
Thank you DevExpress, make people go in circles instead of fixing the issue.
You guys have created 5-6 separate tickets out of this issue and at the end just saying that there is insufficient information. Have you looked at all the other tickets? This issue still persist in v16 and v17 but there is no response from DevExpress. Clearly there is NullReferenceException in your code and instead of finding ways to mitigate or helping customer identifying the issue you guys keep telling us that this issue is related to multithreading. Can you at least put proper error handlers in your code so that it is helpful to people where they should be looking instead of throwing a mile long stack trace which is completely useless.
I would understand if you guys showed similar restraint when asking for product renewal money. You guys suck.
https://www.devexpress.com/Support/Center/Question/Details/T242111/nullreferenceexception-in-devexpress-utils-text-fontscache-getfontcachebyfont
https://www.devexpress.com/Support/Center/Question/Details/T509071/nullreferenceexception-is-thrown-in-the-getfontcachebyfont-method
https://www.devexpress.com/Support/Center/Question/Details/T311768/fontscache-might-be-sharing-gdi-resources-between-different-threads
https://www.devexpress.com/Support/Center/Question/Details/T242111/nullreferenceexception-in-devexpress-utils-text-fontscache-getfontcachebyfont
https://www.devexpress.com/Support/Center/Question/Details/T311768/fontscache-might-be-sharing-gdi-resources-between-different-threads
Hello MAggarwal,
We are truly concerned to hear that our customers encounter such issues. We carefully research each problematic scenario and do our best to help our customers resolve such issues. When we find that an issue is related to our code, we are always ready to make necessary corrections. On the other hand, from our experience, this specific issue quite often happens due to incorrect UI controls access from a background thread. In such scenarios, we cannot fix this issue on our side (WinForms doesn't support this scenario in general). Of course, we can add some check to prevent the exception from being thrown. However, such code will hide the issue, but won't solve it - it will likely occur in some other place in your application. Nevertheless, even when the issue is not caused by our code, we are always happy to assist our customers in resolving it. That's why we ask for a sample project or complete application reproducing the exception. We will look at the code and be able to provide specific recommendations on how to resolve the issue.
There are some issues that can be resolved only by investigating a call stack, and this particular issue is almost impossible to resolve without looking at the project's code.
Anyway, if you have specific suggestions regarding possible improvements in our source code - feel free to share them. We appreciate any feedback.
Indeed, why making several threads…? none of them are fixed and the issue still exists.
Hello Ruud,
Despite the fact that these issues have similar call stacks, each time they occur under different circumstances. That is why we extract such issues in separate threads. I would like to note, that we inspected our code for possible weak points, but all the information provided in these tickets indicate that the issue occurs because of accessing UI controls from non-UI threads. Since none of our customers can provide us with a compilable sample illustrating the problematic behavior, we are unable to give a precise answer why this occurs and modify our source codes correspondingly.
Hi Support team,
I was going to raise a ticket for the same issue until i found this ticket already opened by Steven (feel free if you want me to raise a ticket instead of commenting this).
We are using the "BeginInvoke" and this issue still happens to us in our product, we are using a common method that takes a Control and a string as parameters, then sets the Control.Text = string, here's the method:
internal void SetDisplayText(Control control, string text)
{
try
{
if (control == null)
return;
if (!control.IsHandleCreated)
return;
if (this.InvokeRequired || control.InvokeRequired)
{
BeginInvoke(new UIMarshallingThreadDelegates.ParameterLessTaskDelegate(
delegate
{
control.Text = text;
}));
}
else
{
control.Text = text;
}
}
catch (Exception exception)
{
ServiceLocator.LoggerService.Error("TopOfBook.SetDisplayText => error : " + exception);
}
}
The method above can be called from several threads.
Here's the exception callStack:
2020-05-04 14:27:45:832, P:29220, TH:62308, [Error,Error,4] : TopOfBook.SetDisplayText => error : 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.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth)
at DevExpress.Utils.AppearanceObject.CalcTextSize(GraphicsCache cache, StringFormat sf, String s, Int32 width)
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.ViewInfo.LabelControlViewInfo.CalcTextSize(Boolean useHotkeyPrefix)
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcTextPoints()
at DevExpress.XtraEditors.ViewInfo.LabelControlViewInfo.CalcContentRect(Rectangle bounds)
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcRects()
at DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcViewInfo(Graphics g)
at DevExpress.XtraEditors.LabelControl.LayoutChanged(Boolean isVisualUpdate)
at DevExpress.XtraEditors.LabelControl.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at Com.QuodFinancial.FrontEnd.Gui.Mvp.Views.ForEx.InstrumentSummary.InstrumentSummaryTopOfBook.SetDisplayText(Control control, String text)
The exception is very rare to happen, but in the context we are working at, this should never happen as we can miss big opportunities.
We are using DevExpress 18.2.5.
Thank you,
Chams
Hello,
I've created a separate ticket on your behalf (T888808: NullReferenceException is thrown in the GetFontCacheByFont method). It has been placed in our processing queue and will be answered shortly.