SavchukSergey / AcmeDriver

ACME client
2 stars 1 forks source link

Exception when compiling for NativeAOT #1

Open kurtcodemander opened 1 year ago

kurtcodemander commented 1 year ago

This library doesn't work when used in an application which is compiled for NativeAOT (.net 7):

using var client = await AcmeClient.CreateAcmeClientAsync(AcmeClient.LETS_ENCRYPT_PRODUCTION_URL);

gives exception:

System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter5[<>f__AnonymousType52[System.String[], System.Boolean], System.String[], System.Boolean, System.Object, System.Object]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility

It probably needs to be refactored with System.Text.Json source generators for that to work. Big task?

kurtcodemander commented 1 year ago

If anybody else have this problem I forked and created a version which is using System.Text.Json source generators here:

https://github.com/kurtcodemander/AcmeDriver/tree/jsonsourcegen

There were lots of changes needed and there are still some issues I haven't looked into further. For example, in ProtectedHeader I had to hardcode the Jwk property as either

public EccPublicJwk? Jwk { get; set; }

or

public RsaPublicJwk? Jwk { get; set; }

instead of public PublicJsonWebKey? Jwk { get; set; }

And in AcmeClientRegistration.Sign I'm hardcoding Jwk = (EccPublicJwk) Key.GetPublicJwk() beause of this. Not yet sure how to properly fix it.

Also, I quickly removed abstract keyword on classes because VS showed a bunch of errors, but I'm not sure about this.

But this version works fine with NativeAOT and for my use case so I'm moving on.