[Bug]: Cannot compile with NativeAOT on dotnet 9
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
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.
are you using the lates version? latest version for me even crashing in the debug mode with the latest maui controls update.
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
I am seeing this as well.
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.
Same issues, with release builds not working, only debug.
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>
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.
V11.1.1 has been released with some additions and alterations which may resolve the issues you experienced
Closing out due to AOT support in latest.
This is fixed for us now. Thank you!
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.