Hello,
Recently we started seeing a bug appear that was occurring in the DrawUtility.MeasureStringHelper. We have not yet been able to replicate the error, but below is a part of one of the stack traces that we received.
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.DrawUtility.MeasureStringHelper(Graphics gr, String text, Font font, Size layoutArea, StringFormat stringFormat, Int32& charactersFitted, Int32& linesFilled, Boolean returnElementsFitted, GdiDrawStringFlags drawStringFlags) at Infragistics.Win.DrawUtility.MeasureString(Graphics gr, String text, Font font, GdiDrawStringFlags drawStringFlags) at Infragistics.Win.Utilities.CreateLargestFont(AppearanceData[] appearances, Font baseFont, GdiDrawStringFlags gdiDrawStringFlags) at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.CreateTabMetricsFont(MdiTabGroup tabGroup) at Infragistics.Win.UltraWinTabbedMdi.MdiTabGroup.Infragistics.Win.UltraWinTabs.ITabProvider.CreateMetricsFont() at Infragistics.Win.UltraWinTabs.TabManager.CalculateAllMetrics() at Infragistics.Win.UltraWinTabs.TabManager.VerifyMetrics() at Infragistics.Win.UltraWinTabs.TabManager.get_TabAreaSize() at Infragistics.Win.UltraWinTabbedMdi.TabGroupInfoManager.RecalculateTabGroupInfo(MdiTabGroup tabGroup) at Infragistics.Win.UltraWinTabbedMdi.TabGroupInfoManager.VerifyTabGroupMetrics(MdiTabGroup tabGroup) at Infragistics.Win.UltraWinTabbedMdi.TabGroupInfoManager.GetTabGroupControlRectangle(MdiTabGroup tabGroup) at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.PositionAndSizeTabGroups() at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.DirtyGroupPosition(MdiTabGroup tabGroup) at Infragistics.Win.UltraWinTabbedMdi.MdiTabGroup.DirtyTabManager(TabManagerChangeType changeType) at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.MdiChildVisibilityChanged(MdiTab tab) at Infragistics.Win.UltraWinTabbedMdi.MdiTab.OnMdiChildVisibleChanged(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e) at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e) at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.Show()
The version of Net Advantage we are using is 2009.2. Im sorry I could not offer really any information outside of the stack trace. I believe we probably have something set wrong that only appears under certain conditions. If someone could point me in the right direction to start looking that would be much appreciated.
Has there been any movement on this error that is not included on this post? We are seeing this error on a random yet frequent basis as well. We are on 15.1. I have researched any code dealing with fonts directly and we do not have any unless the AutoScalDimensions and/or the AutoScaleMode set to Font could be part of it.
Hi Dion,
There hasn't been any further movement on this issue on our end. The original customer never responded beyond what you see here.
The majority of the time, issues like this are almost always errors in the application code. It can be caused by the use of threading, or (less frequently) disposing a font that is still being used. There have also been cases where this kind of issue was an error in the Infragistics assemblies, but as far as I know, there are no outstanding issues - so all known issues that would cause this are fixed.
If you can reproduce this error in a small sample project and send it to us, we would, of course, be more than happy to look into it. But if the error is occurring seemingly at random with no discernible pattern, then that would be a strong indication of a threading issue. So the first question I would ask is... is your application using a background thread or do any threading?
There's really nothing we can do here without being able to duplicate the issue. Like I said, this could easily be an issue in the application code that has nothing to do with the Infragistics controls. Even if it's not, without a way to duplicate the exception, there's no way we can track it down. Even if we wanted to attempt to make a fix, how would we know if we fixed it?
According to the call stack, it's blowing up inside this method:
Infragistics.Win.DrawUtility.MeasureStringHelper(Graphics gr, String text, Font font, Size layoutArea, StringFormat stringFormat, Int32& charactersFitted, Int32& linesFilled, Boolean returnElementsFitted, GdiDrawStringFlags drawStringFlags)
I took a quick glance at the source code for that method just to see if there are places in the code where we are accessing properties of an object and not explicitly checking for null. One such place is when we call Graphics.GetHdc(). So if the graphics object were null, that would cause this exception. Of course, I can't imagine any situation in which the Graphics object would be null, and in fact, we check for this in the calling methods and create a temporary graphics object if we don't have one for the screen. It's possible I'm missing something here or that there's a hole I am not seeing, but if that were the case I'd expect to see a lot more reports about this problem. Much more likely is that the application itself is using multiple threads.
There are other objects whose properties are being accessed. There's a VisualStyleRenderer object, but that object is created inside the method, so I can't see how it could possibly be null.
There's a Rectangle, but that's a struct and therefore can't be null.
It accesses the text.Length, so if the text were null, that's another potential exception, but once again, we check for null text before we bother trying to measure the text.
BTW... the original poster was using v9.1 which is over 7 years old. We suggested that he try updating to the latest version, in case this was already fixed, but never got any response as to whether or not he tried that or if it worked. What version are you using?
Is your application using threads? If so, then that would be my #1 suspect for what's causing this exception. Using threading in a Windows Forms application is extremely tricky and it's VERY easy to get yourself into a situation where things outside of your control are crossing the threads without you realizing it and which therefore do not get properly marshaled.
Are you able to consistently reproduce the exception in your application? If so, then you should be able to make a copy of your application and try to reduce it down to something that we could run to see the problem. If not, then that's another one of the hallmarks of a threading issue - inconsistency.
Hi Mike,
I was hoping there would be more activity on this error. I have researched it on my end and simply cannot find out why it is erroring (hence, I cannot provide you a small program). I have thought about the Font being disposed of but am more curious if you think the graphics object may be null. This would give us the Null reference error where a null Font would give us a null parameter error?
Dion