[8.0.100-preview.7.23376.3] NETworkManager Cannot add null to the collection error when trying to open dialog with MahApps library
See original GitHub issueDescription
Starting from dotnet-sdk-8.0.100-preview.5.23264.1, NETworkManager gets this error when it opens a dialog MahApps
Exception Info: System.ArgumentException: Cannot add null to the collection.
at System.Windows.Media.GeneralTransformCollection.AddWithoutFiringPublicEvents(GeneralTransform value)
at System.Windows.Media.GeneralTransformCollection.Add(GeneralTransform value)
Reproduction Steps
Repro steps:
- Run the app with .net8 by updating NETworkManager.runtimeconfig.
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "8.0.0-preview.7.23375.6"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "8.0.0-preview.7.23376.1"
}
- launch the app NETworkManager.exe.
- Click the Continue button if you see it.
- Click any icon from the left menu.
- Click “No Profile found, create one …” like below screenshot.
Expected behavior
Displays create profile dialog.
Actual behavior
The app stops working.
Exception:
Application: NETworkManager.exe
CoreCLR Version: 8.0.23.37506
.NET Version: 8.0.0-preview.7.23375.6
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException: Cannot add null to the collection.
at System.Windows.Media.GeneralTransformCollection.AddWithoutFiringPublicEvents(GeneralTransform value)
at System.Windows.Media.GeneralTransformCollection.Add(GeneralTransform value)
at MS.Internal.Controls.TemplatedAdorner.GetDesiredTransform(GeneralTransform transform)
at System.Windows.Documents.AdornerLayer.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.ScrollContentPresenter.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
at System.Windows.Controls.ScrollViewer.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at NETworkManager.App.Main()
Regression?
Yes
Verify Scenarios:
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23364.1: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23265.7: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23269.37: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23281.8: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.6.23303.5: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.6.23330.14: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23376.3: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23228.7: Pass
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.1.23103.1: Pass
- Windows10 21h2 x64 + dotnet-sdk-6.0.413-win-x64: Pass
- Windows10 21h2 x64 + dotnet-sdk-7.0.110-win-x64: Pass
Known Workarounds
No response
Impact
No response
Configuration
Application Name: NETworkManager OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-8.0.100-preview.7.23376.3 App Github Link: https://github.com/BornToBeRoot/NETworkManager App, App Source, or Repro machine checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1864961
Other information
Findings: When we click add profile button, it displays ProfileDialog usercontrol using Mahapps library ShowMetroDialogAsync method, we noticed when we remove the ValidationRules bindings in UserControl, error does not repro, like this:
<ComboBox x:Name="ComboBoxGroup" Grid.Column="2" Grid.Row="4" Style="{StaticResource EditableComboBox}">
<ComboBox.Text>
<Binding Path="Group">
<Binding.ValidationRules>
<!--Remove this Part-->
<!--<validators:EmptyValidator ValidatesOnTargetUpdated="True" />-->
<!--<validators:GroupNameValidator ValidatesOnTargetUpdated="True" />-->
</Binding.ValidationRules>
</Binding>
</ComboBox.Text>
</ComboBox>
Issue Analytics
- State:
- Created a month ago
- Comments:8 (8 by maintainers)
So I was lucky and found some time to investigate this before my vacation.
I can also repro the same exception, using different code, on .NET 7.0 (which does not have my changes). The issue here really comes down to missing null checks, at least that’s my opinion.
See the attached repro project. adorner_test.zip
@miloush @singhashish-wpf @Junjun-zhao
Verified this issue on latest dotnet-sdk-8.0.100-rc.1.23415.7, it has been fixed. Hence closing it.