Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT support? #2152

Open
emrys90 opened this issue Oct 23, 2023 · 5 comments
Open

NativeAOT support? #2152

emrys90 opened this issue Oct 23, 2023 · 5 comments

Comments

@emrys90
Copy link

emrys90 commented Oct 23, 2023

It would be nice to have full NativeAOT support for RestSharp. It currently logs trimming warnings.

/root/.nuget/packages/restsharp/110.2.0/lib/net7.0/RestSharp.dll : warning IL3053: Assembly 'RestSharp' produced AOT analysis warnings.
@alexeyzimarev
Copy link
Member

The AOT support is blocked by reflections code in AddObject and AddObjectStatic. If you don't use those, it might be already working.

@emrys90
Copy link
Author

emrys90 commented Apr 3, 2024

The AOT support is blocked by reflections code in AddObject and AddObjectStatic. If you don't use those, it might be already working.

Adding attributes to those methods can fix those warnings, and should be able to do so without changing any functionality. Here's a link to an article that explains how to support NativeAOT.
https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/

@vedantmgoyal9
Copy link

If you don't use those, it might be already working.

It still produces warnings. Is there any way we can make it AOT-compatible using the guide suggested by @emrys90?

@alexeyzimarev
Copy link
Member

Ok, I tried now and the embedded XML serialiser creates all sort of pain. Basically, its Serialize function must be annotated as incompatible, which also requires that the interface method must be annotated as well. Which then makes all serialisers incompatible, and nothing works.

I only see one option: remove XML from formats supported by default, move all XML stuff to the XML package (existing one). Thoughts?

@alexeyzimarev
Copy link
Member

Further research (I never used source generator provided by System.Text.Json before) shows that the only way to make it work with trimming is to use JsonSerializerContext created by the user. Therefore, there's no way to implement it with current set of serialisation abstractions as the context needs to be provided when calling the serialiser.

Which means that the scope of change is way beyond "just" adding some attributes as the whole serialisation story will be annotated and the only way it will work with trimming is to make calls without body and with responses that don't require deserialisation.

To me, it kind of defeats the purpose of using RestSharp at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants