Good morning,
I have already read other answers for my same problem and tried to follow the directions given but I must have done something wrong because the problem seems to have worsened.
I have an assembly that contains all the templates I use for communication with servers. I have tried inserting
in the configuration file of the MAUI project but this causes the application to crash on start-up. I did not understand whether it is sufficient to enter the right TrimmerRootAssembly or whether there are also other operations to be performed.
I’ve been trying for days and don’t know what to do anymore.
Thank you very much,
Riccardo
iOS is not a supported platform, it’s No JIT restrictions on Release binaries breaks libraries that use reflection like serializers.
Best you can do is to not link or trim any assemblies that contain your serializable types, e.g. your ServiceModel .dll. Alternatively you could try enabling the interpreter in Release builds.
Something else you can try is using System.Text.Json serializer in JsonApiClient by configuring it in the client on Startup with:
In which case your ServiceStack Server App should use Endpoint Routing so it’s also configured to use System.Text.Json APIs.
Otherwise you’d need to use libraries that specifically supports iOS/No JIT restrictions. If it only breaks in Release mode it’s because Maui uses an interpreter in development/debug builds.
No don’t have any experience with Maui/iOS, but you’d basically need to look for Native AOT/reflection-free compatible libraries, something like source generation in System.Text.Json since it relies on code generation instead of runtime reflection.
Good morning,
I have tried applying all the suggestions you have written but it still doesn’t work. With some of those tips the app crashes immediately on startup.
Can you confirm that I have no choices but to use other libraries for communication between my app and the server?
Right, you’re basically limited to libraries that don’t use reflection which typically suggests using a source-based or code-gen serializer. This thread suggests a lot of work was done in source generated System.Text.Json to make it AOT friendly:
I followed your advice and I am using RestSharp to make the connection between my MAUI app and my server. I normally use your EncryptedClient to connect. With RestSharp I can get the AuthenticateResponse correctly populated but when I then try to make a call I always get an unauthorised exception. Am I missing something? Do I need to pass the session id or token in some post parameter?
Haven’t got any chance to know what the issue is without any information about your Auth configuration, what provider you’re using to Authenticate, whether you’re using session based auth, whether session cookies are populated in subsequent requests, etc.
Thanks a lot for your suggestions. It’s working.
I’m just noticing that I’m having trouble deserializing some classes when using class inheritance.
I only see this issue when using RestSharp, while it didn’t happen with ServiceStack. Is there any setting I can change to work around this?
Unless you’re using a supported serializer I’d be surprised you’d be able to use serialization in iOS/NoJIT, you’d either have to live within the limitations of that serializer or derserialize it into a generic JSON document and use it to manually populate the types yourself.
Also I noticed another Native AOT compatible source generators JSON seiralization solution maintained by one of the developers of the .NET Team:
Personally I wouldn’t use .NET to build an iOS App, its NoJIT restrictions means you don’t know what .NET code or library will break in release/device builds. Flutter / Reactive Native / Kotlin Multiplatform or Swift wouldn’t suffer from these issues.