When running MAUI app in .net 9 in debug it works but without debugging is not

Dani_S 4,051 Reputation points
2025-02-02T06:29:57.61+00:00

Hi,

I moved from maui app in .NET 8 to .NET 9.

The project build but n debug it works but without debugging the login page is not opened.

I checked all nugets packages and moved to last.

================================




<ItemGroup>

 <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />

<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />

<PackageReference Include="System.Management" Version="9.0.1" />

<PackageReference Include="Telerik.UI.for.Maui" Version="8.0.0" />

<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />

<PackageReference Include="Autofac" Version="8.2.0" />

<PackageReference Include="DotNetZip" Version="1.16.0" />

</ItemGroup>

<!-- Windows -->

<ItemGroup Condition="$(TargetFramework.Contains('-windows')) == true">

<PackageReference Include="WindowsAPICodePack" Version="8.0.6" />

</ItemGroup>

This is my xaml.cs

===========

public partial class App : Application

 {

private static Mutex mutex = new Mutex(true, Assembly.GetEntryAssembly().GetName().Name);

public App()

 {

if (!mutex.WaitOne(TimeSpan.Zero, true))

 {

Current.Quit();

Environment.Exit(0);

 }

InitializeComponent();

MainPage = new LoginPage();

 }

protected override Window CreateWindow(IActivationState? activationState)

 {

Window window = base.CreateWindow(activationState);

try

 {

window.Stopped += async(s,e) =>

 {

if (!string.IsNullOrEmpty(LoginConfigurations.GetInstance().SessionToken ))

 {

var container = new Bootstrapper().Bootstrap();

IAutomationApiClient automationApiClient = container.Resolve<IAutomationApiClient>();

var results = await automationApiClient.PostLogOut($"{LoginConfigurations.GetInstance().Portal}/api/GSPortal/PostLogOut/false", LoginConfigurations.GetInstance().SessionToken);

if(results)

 {

App.Current.Quit();

 }

 }

 };

 }

catch (Exception)

 {

 }

return window;



 }

 }

}

  1. I comment the mutex code + CreateWindow same problem.

How to solve the problem ?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,887 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Bruce (SqlWork.com) 70,611 Reputation points
    2025-02-03T17:52:58.86+00:00

    typically this is caused by using a library that does not support AOT (uses reflection, etc):

    https://learn.microsoft.com/en-us/dotnet/maui/deployment/nativeaot?view=net-maui-9.0

    you can disable AOT. (I'd suspect autofac, and replace it with Services).

    https://github.com/abpframework/abp/issues/21019


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.