Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

[Bug]: Cannot compile with NativeAOT on dotnet 9

Open qrzychu opened this issue 8 months ago • 3 comments

Describe the bug 🐞

I am trying to make an Avalonia app for Windows (later MacOS), I wanted to use Akavache to store some user settings in encypted blob in a custom location (not using the static stuff).

Works fine in Debug, but after publishing with native AOT I get the error:

Unhandled exception. System.InvalidOperationException: There is not a valid operation queue
   at System.Reactive.Subjects.AsyncSubject`1.GetResult() + 0x129
   at Program.<<Main>$>d__0.MoveNext() + 0x144
--- End of stack trace from previous location ---
   at Program.<Main>(String[] args) + 0x24

I made a reproduciton repo: https://github.com/qrzychu/Akavache.AOT-Sample

Is native oat even possible? I went through the code and it seems to use a lot of reflection. I added proper instrctions to not trim Akavache assemblies, but maybe I am missing something.

If AOT is not in the scope, I will just find a different solution

Step to reproduce

all in repo

I use the publish output instead of native because I haven't yet figured out how to copy all needed native binaries (like SQLite in case of Akavache)

Reproduction repository

https://github.com/qrzychu/Akavache.AOT-Sample

Expected behavior

This should happen...

Screenshots 🖼️

No response

IDE

Rider Windows

Operating system

No response

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

IDE doesn't really matter, you have to run the native binary created by dotnet publish

qrzychu avatar Apr 17 '25 14:04 qrzychu

I have AOT disabled and the trimmer is now killing Akavache as the constructors on the various .Registration classes are being trimmed away. Only just started happening on release builds in the last month. Uncertain if it is an Akavache or MAUI issue.

We just excluded Akavache from trimming via a linker XML for the time being.

RobTF avatar Apr 24 '25 14:04 RobTF

are you using the lates version? latest version for me even crashing in the debug mode with the latest maui controls update.

EmilAlipiev avatar May 03 '25 13:05 EmilAlipiev

We removed the old xml file that specified the linker exemptions, this is likely causing it, so at some point maybe @ChrisPulman will reintroduce it

ths is because we are adding all the microsoft attributes to indicate where we support AOT or not, but it doesn't seem to be honoiring not linking at the compilr sage

glennawatson avatar May 03 '25 14:05 glennawatson

I am seeing this as well.

jerebear12 avatar Jul 10 '25 15:07 jerebear12

Bumping. I am having this issue with AOT disabled on all builds. Despite using Registrations.Start(<MyAppName>); in my CreateMauiApp() code, it is being removed and causing crashes in both iOS and Android during release builds.

rileyyy avatar Jul 20 '25 09:07 rileyyy

Same issues, with release builds not working, only debug.

chris-oswald avatar Aug 06 '25 13:08 chris-oswald

There is a new version of Akavache pending release V11.0.x

I tested your repo using the new version and it runs with this project configuration

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <RootNamespace>Akavache.AOT_Sample</RootNamespace>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>
    
    <ItemGroup>
        <TrimmerRootAssembly Include="Akavache" />
        <TrimmerRootAssembly Include="Akavache.SystemTextJson" />
        <TrimmerRootAssembly Include="Akavache.Sqlite3" />
        <TrimmerRootAssembly Include="Splat.Builder" />
        <!--        <TrimmerRootAssembly Include="Akavache.Mac"/>,-->
        <!--        <TrimmerRootAssembly Include="Akavache.Deprecated"/>-->
        <!--        <TrimmerRootAssembly Include="Akavache.Mobile"/>,-->
        <!--        <TrimmerRootAssembly Include="Akavache.Drawing"/>-->
    </ItemGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="9.0.4" />
      <PackageReference Include="Akavache.Sqlite3" Version="11.0.*" />
      <PackageReference Include="Akavache.SystemTextJson" Version="11.0.*" />
    </ItemGroup>

</Project>
Image

ChrisPulman avatar Aug 24 '25 16:08 ChrisPulman

As a matter of completeness, you declared

<TrimmerRootAssembly Include="##Assembly##" /> You need to include the RootMode to ensure the correct operation

<TrimmerRootAssembly Include="##Assembly##" RootMode="All" /> or <TrimmerRootAssembly Include="##Assembly##" RootMode="EntryPoint" /> or <TrimmerRootAssembly Include="##Assembly##" RootMode="CopyUsed" />

For libraries with reflection (which ReactiveUI has much of) or dynamic access, All is the safest — especially if you're finding trimming issues.

ChrisPulman avatar Aug 24 '25 19:08 ChrisPulman

V11.1.1 has been released with some additions and alterations which may resolve the issues you experienced

ChrisPulman avatar Sep 03 '25 00:09 ChrisPulman

Closing out due to AOT support in latest.

glennawatson avatar Sep 05 '25 00:09 glennawatson

This is fixed for us now. Thank you!

jerebear12 avatar Sep 19 '25 21:09 jerebear12

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Oct 04 '25 00:10 github-actions[bot]