Ticket T517263
Visible to All Users

The NullReference exception occurs when the LayoutChanged method is called

created 8 years ago

[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()

Show previous comments (4)
DevExpress Support Team 7 years ago

    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.

    QF QF
    Quod Financial 5 years ago

      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

      Nadezhda (DevExpress Support) 5 years ago

        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.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.