question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Regression] NullReferenceException on maximized MDI child icon changes with 150% DPI

See original GitHub issue
  • .NET Core Version: 6.0.1

  • Have you experienced this same bug with .NET Framework?: No

Problem description:

NullReferenceException in System.Windows.Forms.ToolStripItem.InvalidateItemLayout when you try to change Icon on maximized child form (only with 150% DPI):

https://user-images.githubusercontent.com/17767561/150631131-044884bc-7fcf-41c0-9ebb-6f76820ccbc6.mp4

Exception details
************** Текст исключения **************
System.NullReferenceException: Object reference not set to an instance of an object.
 at System.Windows.Forms.ToolStripItem.InvalidateItemLayout(String affectedProperty)
 at System.Windows.Forms.ToolStripItem.set_Image(Image value)
 at System.Windows.Forms.MdiControlStrip.updateIcon()
 at System.Windows.Forms.Form.UpdateWindowIcon(Boolean redrawFrame)
 at System.Windows.Forms.Form.set_Icon(Icon value)
 at WinFormsCoreTest.Form2.button2_Click(Object sender, EventArgs e) in D:\save\projects\core tests\WinFormsCoreTest_MDI_Icon\Form2.cs:line 33
 at System.Windows.Forms.Control.OnClick(EventArgs e)
 at System.Windows.Forms.Button.OnClick(EventArgs e)
 at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
 at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
 at System.Windows.Forms.Control.WndProc(Message& m)
 at System.Windows.Forms.ButtonBase.WndProc(Message& m)
 at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
 at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)


************** Загруженные сборки **************
System.Private.CoreLib
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Private.CoreLib.dll
----------------------------------------
WinFormsCoreTest
  Версия сборки: 1.0.0.0
  Версия Win32: 1.0.0.0
  CodeBase (база кода): file:///C:/Users/Shapiro/Desktop/net6.0-windows/WinFormsCoreTest.dll
----------------------------------------
System.Runtime
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Runtime.dll
----------------------------------------
System.Windows.Forms
  Версия сборки: 6.0.1.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/System.Windows.Forms.dll
----------------------------------------
System.ComponentModel.Primitives
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.ComponentModel.Primitives.dll
----------------------------------------
System.Windows.Forms.Primitives
  Версия сборки: 6.0.1.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/System.Windows.Forms.Primitives.dll
----------------------------------------
System.Runtime.InteropServices
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Runtime.InteropServices.dll
----------------------------------------
System.Drawing.Primitives
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Drawing.Primitives.dll
----------------------------------------
System.Collections.Specialized
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Collections.Specialized.dll
----------------------------------------
System.Threading
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Threading.dll
----------------------------------------
System.Diagnostics.TraceSource
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Diagnostics.TraceSource.dll
----------------------------------------
System.Collections
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Collections.dll
----------------------------------------
System.Drawing.Common
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/System.Drawing.Common.dll
----------------------------------------
Microsoft.Win32.Primitives
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/Microsoft.Win32.Primitives.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Threading.Thread
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Threading.Thread.dll
----------------------------------------
Accessibility
  Версия сборки: 4.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/Accessibility.dll
----------------------------------------
System.ComponentModel.TypeConverter
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.ComponentModel.TypeConverter.dll
----------------------------------------
Microsoft.Win32.SystemEvents
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Collections.Concurrent
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Collections.Concurrent.dll
----------------------------------------
System.ComponentModel
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.ComponentModel.dll
----------------------------------------
System.Numerics.Vectors
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Numerics.Vectors.dll
----------------------------------------
System.Memory
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Memory.dll
----------------------------------------
System.Resources.Extensions
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/System.Resources.Extensions.dll
----------------------------------------
System.Drawing
  Версия сборки: 6.0.1.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/System.Drawing.dll
----------------------------------------
System.ObjectModel
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.ObjectModel.dll
----------------------------------------
System.Linq
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Linq.dll
----------------------------------------
System.Collections.NonGeneric
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Collections.NonGeneric.dll
----------------------------------------
System.Runtime.CompilerServices.Unsafe
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Runtime.CompilerServices.Unsafe.dll
----------------------------------------
System.Runtime.Loader
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Runtime.Loader.dll
----------------------------------------
System.Windows.Forms.resources
  Версия сборки: 6.0.1.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.1/ru/System.Windows.Forms.resources.dll
----------------------------------------
System.Private.Uri
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Private.Uri.dll
----------------------------------------
System.Diagnostics.StackTrace
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Diagnostics.StackTrace.dll
----------------------------------------
System.Reflection.Metadata
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Reflection.Metadata.dll
----------------------------------------
System.Collections.Immutable
  Версия сборки: 6.0.0.0
  Версия Win32: 6.0.121.56705
  CodeBase (база кода): file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Collections.Immutable.dll
----------------------------------------

It’s obvious that the regression was somehow introduced here. Interesting thing to note that despite the exception, the icon changes successfully.

Expected behavior: No Exception.

Minimal repro: WinFormsCoreTest_MDI_Icon.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:24 (24 by maintainers)

github_iconTop GitHub Comments

2reactions
jbhensleycommented, Jan 31, 2022

I’ve submitted a fix for the NRE. It’s a doozy.

As for slight variations in icon size of two originally same-sized icons at different DPI, I did not investigate that further but suspect we’re dealing with rounding differentials in the scaling logic. I’m not sure if that rises to the level of being an actual concern.

I think that covers everything, but let me know if I’m overlooking something.

2reactions
RussKiecommented, Jan 29, 2022

@kirsan31 @jbhensley thanks for looking further into this, assigning to you for now. Please holler back if you get stuck.

If this issue does not repro on .NET Framework 4.6, 4.7 and 4.8, it is probably a good idea to bisect and try to establish which commit has introduced the regression.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with icon on creating new maximized MDI child ...
I set a a child form's Icon property, and the icon shows up correctly in the top left corner of the form. I...
Read more >
2013 v3 | WinForms Edition Release History
Conflicts property raised NullReference exception if no conflicts exist. TopicMap property could throw NullReference exception. Editor for WinForms 20133.206.
Read more >
DotNetBar for Windows Forms Release Notes
MDIForm=null setting if property was assigned but set to null before MDI Form has been loaded; Fixed: Creating Docked Bar with the DotNetBarManager...
Read more >
Archives | The Wiert Corner - irregular stream of stuff
Windows: starting Chrome in full-screen kiosk mode from a batch file ... Interesting thread on how to approach Hi-DPI and DPI changes with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found