Search code examples
c#avalonia

Program.cs(18, 44): [CS1061] 'AppBuilder' does not contain a definition for 'UsePlatformDetect' and no accessible extension method 'UsePlatformDetect'


  Program.cs(18, 44): [CS1061] 'AppBuilder' does not contain a definition for 'UsePlatformDetect' and no accessible extension method 'UsePlatformDetect' accepting a first argument of type 'AppBuilder' could be found (are you missing a using directive or an assembly reference?)

So here is my code :

using System;
using Avalonia;
using Avalonia.ReactiveUI;

namespace AvaloniaCrossPlatformApplication1.Desktop
{
    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 void Main(string[] args) => BuildAvaloniaApp()
            .StartWithClassicDesktopLifetime(args);

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

My avalonia version is avalonia.0.10.13.nupkg.sha512

i'am using the basic template.

It seems that there is no UsePlatformDetect on Avalonia ...

I used jetbrain rider & dotnet new -i Avalonia.Templates

to generate the template.

Any ideas ? I'am on ubuntu 22.04.

Regards


Solution

  • The UsePlatformDetect extension has its definition in the Avalonia.Desktop assembly, so you have to add a reference to it in your .csproj

    <PackageReference Include="Avalonia.Desktop" Version="0.10.13" />