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.

[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 issue

Description

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:

  1. 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"
      }
  1. launch the app NETworkManager.exe.
  2. Click the Continue button if you see it.
  3. Click any icon from the left menu.
  4. Click “No Profile found, create one …” like below screenshot.

screenshot1

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:

  1. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23364.1: Fail
  2. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23265.7: Fail
  3. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23269.37: Fail
  4. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23281.8: Fail
  5. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.6.23303.5: Fail
  6. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.6.23330.14: Fail
  7. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23376.3: Fail
  8. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23228.7: Pass
  9. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.1.23103.1: Pass
  10. Windows10 21h2 x64 + dotnet-sdk-6.0.413-win-x64: Pass
  11. 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>

@dotnet-actwx-bot @dotnet/compat

Issue Analytics

  • State:closed
  • Created a month ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
batzencommented, Aug 8, 2023

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

1reaction
Junjun-zhaocommented, Aug 16, 2023

Verified this issue on latest dotnet-sdk-8.0.100-rc.1.23415.7, it has been fixed. Hence closing it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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