Search code examples
c#maui

.NET MAUI - "Nested types are not supported: ParentFolder.View"


In my MAUI project, I wanted to organise some views into sub folders.

As a result, I have a path that looks like this: Project -> _Views -> Authentication -> FileView.xaml.

This has been working fine for a month, but after changing something in AppShell.xaml I started getting Nested types are not supported: Authentication.FileView.

I tried to clean the project, rebuilt it, deleted temp files (bin, vs...), nothing has worked: As soons as I modify my AppShell.xaml the error comes up.

I cannot see anywhere something that says we cannot have subfolders, and it feels a bit odd this would be a limitation of MAUI.

I thought it might be a path definition problem, but I cannot see anything, I am hoping someone with fresh eyes might be able to pick something up:

AppShell.xaml

    <Shell
        x:Class="Project.AppShell"
        xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:Project"
        xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
        xmlns:views="clr-namespace:Project._Views"
        xmlns:strings="clr-namespace:Project.Langs"
        xmlns:viewModels="clr-namespace:Project._ViewModels"
    ...
        <ShellContent
            Title="FileView"
            FlyoutItemIsVisible="False"
            ContentTemplate="{DataTemplate views:Authentication.FileView}"
            Route="route"      
            />
    ...
    </Shell>

FileView.xaml

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:strings="clr-namespace:Project.Langs"
                 xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
                 x:Class="Project._Views.Authentication.FileView"
                 Title="SplashView"
                 Shell.NavBarIsVisible="False"
                 Shell.FlyoutBehavior="Disabled">
    
    </ContentPage>

Solution

  • Have a separate namespace for referring your FileView. This avoids confusion with a property access in some contexts.

    <Shell
        x:Class="Project.AppShell"
        xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:Project"
        xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
        xmlns:views="clr-namespace:Project._Views"
        xmlns:auth="clr-namespace:Project._Views.Authentication"
        xmlns:strings="clr-namespace:Project.Langs"
        xmlns:viewModels="clr-namespace:Project._ViewModels"
    ...
        <ShellContent
            Title="FileView"
            FlyoutItemIsVisible="False"
            ContentTemplate="{DataTemplate auth:FileView}"
            Route="route"      
            />
    ...
    </Shell>