Repository navigation
Commit dac7031
committed
fix: Allow SavedCookbooks.json to be deserialized under NativeAOT
Context: https://github.com/unoplatform/uno/issues/20533#issuecomment-3715971106
Context: unoplatform/uno.extensions#3008
Context: unoplatform/uno.extensions#2996
Uno 6.5.x has (very) preliminary support for NativeAOT!
Let's try it:
sed -i '' 's/"Uno.Sdk": ".*"/"Uno.Sdk": "6.5.0-dev.104"/g' global.json
dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
-bl Chefs/Chefs.csproj -p:SelfContained=true -p:UseSkiaRendering=true \
-p:PublishAot=true -p:IsAotCompatible=true
Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs
From the launch screen:
* Click **Skip**
* Click ** Sign in with Apple**
* Click **❤️ Favorites**
Result: no favorited recipes are shown.
Worse, no useful error messages are written to the Terminal.
What's wrong?!
Part of what's wrong is unoplatform/uno.extensions#3008: the codepath
that *should* be generating an error message writes the error message
to a Dependency-Injection -originated `ILogger<BaseMockEndpoint>`
instance, which only produces data if `.UseLogging()` is used, which
was disabled for reasons nobody remembers.
Re-enable `.UseLogging()`, and *now* we see why it fails:
fail: Chefs.Client.Mock.BaseMockEndpoint[0]
Failed to load SavedCookbooks.json
System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled() + 0x27
at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer() + 0x2e
at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions, Type) + 0x2d
at System.Text.Json.JsonSerializer.Deserialize(String, Type, JsonSerializerOptions) + 0x1d
at Uno.Extensions.Serialization.SerializerExtensions.FromString[T](ISerializer, String) + 0x39
at Chefs.Client.Mock.BaseMockEndpoint.<LoadData>d__3`1.MoveNext() + 0x144
Sort of. We see that it fails because we're missing `JsonTypeInfo<T>`
for *something* that is required, but what?
Enter unoplatform/uno.extensions#2996, which adds support for
`$(JsonSerializerIsReflectionEnabledByDefault)`=false to
Uno.Extensions.Serialization, providing a better error message:
fail: Chefs.Client.Mock.BaseMockEndpoint[0]
Failed to load SavedCookbooks.json
System.InvalidOperationException: Reflection-based serialization has been disabled for this application.
Use the IServiceCollection.AddJsonTypeInfoResolvers() or IHostBuilder.UseSerializationResolvers() extension methods to enable JSON deserialization for type `System.Collections.Generic.List`1[[System.Guid, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]`.
With a bit of squinting, we see that the type we need to support is
`List<Guid>`.
Update `MockEndpointContext` to support serializing `List<Guid>`:
[JsonSerializable(typeof(List<Guid>))]
partial class MockEndpointContext;
Then update `ConfigureSerialization()` so that it's supported:
services
.AddJsonTypeInfo(MockEndpointContext.Default.ListGuid);
This allows `List<Guid>` to be properly deserialized, which in turn
allows **❤️ Favorites** to actually show favorited items.1 parent a49f36b commit dac7031
2 files changed
Lines changed: 8 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
0 commit comments