uno.extensions icon indicating copy to clipboard operation
uno.extensions copied to clipboard

NullReferenceException when calling `.Region(r => r.Attached(true))`

Open johnnyelwailer opened this issue 2 years ago • 4 comments
trafficstars

Good day I am using C# markup and trying to implement a basic NavigationView.

Current behavior

I got a basic NavigationView displayed, but clicking on an item would not lanch a navigation.

I then went over the docs (for which there is unfortunately no Version for C# Markup): https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Tutorials/Navigation/Advanced/HowTo-UseNavigationView.html

It says something like add the uen:Region.Attached everywhere, I don't understand why, but I assumed it is important. So I found the equivalent in C#: .Region(r => r.Attached(true))

Since I added that to any of the elements in the Shell, I am receiving a Null Reference Exception: Logger needs to be set

Expected behavior

There should be no error, and navigation should work

How to reproduce it (as minimally and precisely as possible)

Create an app from the template activating the routing using regions, and csharp markup.

public sealed partial class Shell : UserControl, IContentControlProvider
{
    public Shell()
    {
        this.Content(
            new Border()
                .Child(
                    new NavigationView()
                        .Region(r => r.Attached(true))
                        .PaneDisplayMode(NavigationViewPaneDisplayMode.LeftMinimal)
                        .MenuItems(
                            new NavigationViewItem()
                                .Content("Home")
                                .Icon(new SymbolIcon(Symbol.Home))
                                .Region(r => r.Name("Main"))
                         .Content(
                            new ExtendedSplashScreen()
                             .Region(r => r.Attached(true))
                             .Assign(out var view)
                             .HorizontalContentAlignment(HorizontalAlignment.Stretch)
                             .VerticalContentAlignment(VerticalAlignment.Stretch)
                             .LoadingContentTemplate<object>(_ => new Grid()
                                .RowDefinitions(new GridLength(2, GridUnitType.Star), new GridLength(1, GridUnitType.Star))
                                .Children(
                                    new ProgressRing()
                                        .Grid(row: 1)
                                        .VerticalAlignment(VerticalAlignment.Center)
                                        .HorizontalAlignment(HorizontalAlignment.Center)
                                        .Height(100)
                                        .Width(100)
                                )
                            )
                         )
                    )
                .HorizontalAlignment(HorizontalAlignment.Stretch)
                .VerticalAlignment(VerticalAlignment.Stretch)
            )
            .Background(Theme.Brushes.Background.Default);

        ContentControl = view;
    }

    public ContentControl ContentControl { get; }
}

Environment

Winui, .Net 8

Package Version(s): UNO.WinUi 5.0.41

Affected platform(s):

  • [ ] iOS
  • [ ] Android
  • [ ] WebAssembly
  • [ ] WebAssembly renders for Xamarin.Forms
  • [x ] Windows
  • [ ] Build tasks

Visual Studio:

  • [ ] 2017 (version: )
  • [x ] 2022 (version: 17.8)
  • [ ] for Mac (version: )

Relevant plugins:

  • [ ] Resharper (version: )

Anything else we need to know?

I saw there was already a bufix related to this exception here: https://github.com/unoplatform/uno.extensions/issues/1732 Unfortunately, it doesn't seem to apply for me

johnnyelwailer avatar Nov 18 '23 20:11 johnnyelwailer

@nickrandolph this appears to be a bug in Extensions.Navigation

Exception: System.NullReferenceException
Message: Logger needs to be set
Source: Uno.Extensions.Navigation.UI
StackTrace:
   at Uno.Extensions.Navigation.UI.Region.get_Logger()
   at Uno.Extensions.Navigation.UI.Region.AttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at ABI.Microsoft.UI.Xaml.PropertyChangedCallback.Do_Abi_Invoke(IntPtr thisPtr, IntPtr d, IntPtr e)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IDependencyObjectMethods.SetValue(IObjectReference _obj, DependencyProperty dp, Object value)
   at Microsoft.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Uno.Extensions.Navigation.UI.RegionPropertyBuilder.Attached(Boolean attached)
   at UnoApp3.Presentation.Shell.<>c.<.ctor>b__0_0(RegionPropertyBuilder r) in Y:\temp\UnoApp3\UnoApp3\UnoApp3\Presentation\Shell.cs:line 11

UnoApp3.zip

dansiegel avatar Dec 22 '23 14:12 dansiegel

Any workaround?

xperiandri avatar Mar 25 '24 09:03 xperiandri

4.1.0-dev.74 still have a bug

xperiandri avatar Mar 25 '24 09:03 xperiandri

So I figured out what is wrong @johnnyelwailer see explanation in https://github.com/unoplatform/uno.extensions/issues/215

xperiandri avatar Mar 26 '24 15:03 xperiandri