Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

failed to open packed App on macOS

Open laolarou726 opened this issue 2 years ago • 2 comments

Describe the bug I used Dotnet.Bundle package and MSBuild command to generate macOS bundle. But the binary failed to start. However, if I launch the application directly through the command line using:


/LauncherX.Avalonia.app/Contents/MacOS/LauncherX.Avalonia

The application will start normally.

To Reproduce Steps to reproduce the behavior:

  1. Add Dotnet.Bundle package
  2. Add following configuration in .csproj:

<PropertyGroup Condition="'$(IsOSX)'=='true'">
    <CFBundleName>$(AssemblyName)</CFBundleName>
    <CFBundleDisplayName>$(AssemblyName)</CFBundleDisplayName>
    <CFBundleIdentifier>com.$(username).$(AssemblyName)</CFBundleIdentifier>
    <CFBundleVersion>1.0.0</CFBundleVersion>
    <CFBundlePackageType>APPL</CFBundlePackageType>
    <!--<CFBundleSignature>????</CFBundleSignature>-->
    <CFBundleExecutable>$(AssemblyName)</CFBundleExecutable>
    <CFBundleIconFile>Assets/app.icns</CFBundleIconFile>
    <NSPrincipalClass>NSApplication</NSPrincipalClass>
    <NSHighResolutionCapable>true</NSHighResolutionCapable>
    <CFBundleShortVersionString>1.0</CFBundleShortVersionString>
    <!-- Optional -->
    <NSRequiresAquaSystemAppearance>true</NSRequiresAquaSystemAppearance>
  </PropertyGroup>

  1. use the following command to build:

dotnet restore -r osx-x64
dotnet msbuild -t:BundleApp -p:RuntimeIdentifier=osx-x64 -property:Configuration=Release -p:UseAppHost=true

  1. get the bundle image

Expected behavior Application should launch successfully without crashing.

Screenshots and Logs image

detail.txt

Desktop (please complete the following information):

  • OS: macOS Monterey
  • Version 12.6

laolarou726 avatar Sep 18 '22 06:09 laolarou726

Your app appears to be throwing a managed exception, try logging it in Main in program.cs . One common cause of this is the current directory is different when a program is run as a .app .

ahopper avatar Sep 18 '22 07:09 ahopper

Bundle also contains stuff related to requested permissions. If the problem is not related to the working directory, it's probably permission-related.

mysteryx93 avatar Sep 20 '22 01:09 mysteryx93

Your app appears to be throwing a managed exception, try logging it in Main in program.cs . One common cause of this is the current directory is different when a program is run as a .app .

But it seems I can run the executable using the terminal command.

laolarou726 avatar Sep 27 '22 05:09 laolarou726

Also check Console macOS app, as it can contain additional information about your app why it was closed/crashed. Especially if it's related to some permissions or security related problems.

maxkatz6 avatar Sep 27 '22 19:09 maxkatz6

Your app appears to be throwing a managed exception, try logging it in Main in program.cs . One common cause of this is the current directory is different when a program is run as a .app .

But it seems I can run the executable using the terminal command.

running as a .app runs in a different environment to running the exe directly as in your command line, one thing that is different is the working directory another is probably security options. I have had exactly the same thing happen, logging the exception should tell you the issue.

ahopper avatar Sep 29 '22 18:09 ahopper

Problem solved. I just changed the path for the conf file. Now everything is working as expected!

laolarou726 avatar Oct 18 '22 17:10 laolarou726