Home > Software design >  Running your app on a Raspberry Pi with Raspbian Lite
Running your app on a Raspberry Pi with Raspbian Lite

Time:06-03

I can't cope with running the avalonia application on raspbian lite. I am using raspberry 3b and RaspbianLite OS. I'm using this tutorial:

https://docs.avaloniaui.net/guides/deep-dives/running-on-raspbian-lite-via-drm

Sorry, but I get this error:

AXN0002 - XamlX.XamlParseException: Unable to resolve type MainView from namespace clr-namespace:AvaloniaRaspbianLiteDrm row 10, position 4

This is what my MainWindow looks like:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"
        mc:Ignorable="d"
        d:DesignWidth="800"
        d:DesignHeight="450"
        x:Class="AvaloniaRaspbianLiteDrm.Views.MainWindow"
        Title="AvaloniaRaspbianLiteDrm">
  <avaloniaRaspbianLiteDrm:MainView/>
</Window>

MainSingleView:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"
             mc:Ignorable="d"
             d:DesignWidth="800"
             d:DesignHeight="450"
             x:Class="AvaloniaRaspbianLiteDrm.Views.MainSingleView">
  <avaloniaRaspbianLiteDrm:MainView/>
</UserControl>

MainView:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             d:DesignWidth="800"
             d:DesignHeight="450"
             x:Class="AvaloniaRaspbianLiteDrm.Views.MainView">
  <StackPanel HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Margin="30"
              Spacing="30">
    <TextBlock FontSize="25">
      Welcome to Avalonia! The best XAML framework ever ♥
    </TextBlock>
    <Slider />
  </StackPanel>
</UserControl>

Program.cs :

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;
using System.Linq;
using System.Threading;

namespace AvaloniaRaspbianLiteDrm
{
    internal class Program
    {
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        [STAThread]
        public static int Main(string[] args)
        {
            var builder = BuildAvaloniaApp();
            if (args.Contains("--drm"))
            {
                SilenceConsole();
                return builder.StartLinuxDrm(args);
            }

            return builder.StartWithClassicDesktopLifetime(args);
        }

        private static void SilenceConsole()
        {
            new Thread(() =>
            {
                Console.CursorVisible = false;
                while (true)
                    Console.ReadKey(true);
            })
            { IsBackground = true }.Start();
        }

        // Avalonia configuration, don't remove; also used by visual designer.
        public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
                .UsePlatformDetect()
                .LogToTrace()
                .UseReactiveUI();
    }
}

App.xaml.cs:

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaRaspbianLiteDrm.ViewModels;
using AvaloniaRaspbianLiteDrm.Views;

namespace AvaloniaRaspbianLiteDrm
{
    public partial class App : Application
    {
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public override void OnFrameworkInitializationCompleted()
        {
            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
               desktop.MainWindow = new MainWindow();
          
            else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
                singleView.MainView = new MainSingleView();

            base.OnFrameworkInitializationCompleted();
        }
    }
}

CodePudding user response:

The message is that the MainView cannot be found in the avaloniaRaspbianLiteDrm namespace.

As I can see in your example the MainView (as seen on x:Class="AvaloniaRaspbianLiteDrm.Views.MainView) is inside the AvaloniaRaspbianLiteDrm.Views namespace. You probably forgot that there is a Views namespace.

You should probably change the

xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"

to

xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm.Views"

Make sure that the codebehind file MainView.xaml.cs also uses the AvaloniaRaspbianLiteDrm.Views namespace.

  • Related