diff options
author | jacalvar <jacalvar@microsoft.com> | 2022-11-11 13:52:57 +0300 |
---|---|---|
committer | jacalvar <jacalvar@microsoft.com> | 2022-11-11 19:40:49 +0300 |
commit | 7f9a978a8618ff5e3a05d32fb0d5e372e790d1db (patch) | |
tree | 5c2760b05740d9930944dfcea0773836da033b09 | |
parent | 66bba56c4edf65ea3ab8141b5aef2652a3565929 (diff) |
Fix linker issuesjaviercn/workaround-linker-regression
5 files changed, 52 insertions, 20 deletions
diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml b/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml new file mode 100644 index 0000000000..a1d22402e9 --- /dev/null +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication"> + <type fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationContext`1" preserve="all" /> + </assembly> +</linker> diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj b/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj index 345236f694..c9bb1d3009 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj @@ -40,6 +40,10 @@ <Content Remove="$(YarnWorkingDir)**" /> <None Include="$(YarnWorkingDir)*" Exclude="$(YarnWorkingDir)node_modules\**" /> + + <EmbeddedResource Include="ILLink.Descriptors.xml"> + <LogicalName>ILLink.Descriptors.xml</LogicalName> + </EmbeddedResource> <UpToDateCheckInput Include="@(YarnInputs)" Set="StaticWebassets" /> <UpToDateCheckOutput Include="@(YarnOutputs)" Set="StaticWebassets" /> diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs index 870b42e3db..56844d476e 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs @@ -14,6 +14,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication; [JsonConverter(typeof(Converter))] public sealed class InteractiveRequestOptions { + private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions + { + MaxDepth = 32, + PropertyNameCaseInsensitive = true, + }; + /// <summary> /// Gets the request type. /// </summary> @@ -86,17 +92,29 @@ public sealed class InteractiveRequestOptions static TValue Deserialize(JsonElement element) => element.Deserialize<TValue>(); } - internal string ToState() => JsonSerializer.Serialize(this, InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions); - - internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize( + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This method serializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] + internal string ToState() => JsonSerializer.Serialize(this, SerializerOptions); + + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This method deserializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] + internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize<InteractiveRequestOptions>( state, - InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions); + SerializerOptions); internal class Converter : JsonConverter<InteractiveRequestOptions> { + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This converter reads 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] public override InteractiveRequestOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - var requestOptions = JsonSerializer.Deserialize(ref reader, InteractiveRequestOptionsSerializerContext.Default.OptionsRecord); + var requestOptions = JsonSerializer.Deserialize<InteractiveOptions>(ref reader, options); return new InteractiveRequestOptions { @@ -107,26 +125,27 @@ public sealed class InteractiveRequestOptions }; } + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This converter writes 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] public override void Write(Utf8JsonWriter writer, InteractiveRequestOptions value, JsonSerializerOptions options) { JsonSerializer.Serialize( writer, - new OptionsRecord(value.ReturnUrl, value.Scopes, value.Interaction, value.AdditionalRequestParameters), - InteractiveRequestOptionsSerializerContext.Default.OptionsRecord); + new InteractiveOptions { ReturnUrl = value.ReturnUrl, Scopes = value.Scopes, Interaction = value.Interaction, AdditionalRequestParameters = value.AdditionalRequestParameters }, + options); } - internal record struct OptionsRecord( - [property: JsonInclude] string ReturnUrl, - [property: JsonInclude] IEnumerable<string> Scopes, - [property: JsonInclude] InteractionType Interaction, - [property: JsonInclude] Dictionary<string, object> AdditionalRequestParameters); - } -} + public struct InteractiveOptions + { + public string ReturnUrl { get; set; } -[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = false)] -[JsonSerializable(typeof(InteractiveRequestOptions))] -[JsonSerializable(typeof(InteractiveRequestOptions.Converter.OptionsRecord))] -[JsonSerializable(typeof(JsonElement))] -internal partial class InteractiveRequestOptionsSerializerContext : JsonSerializerContext -{ + public IEnumerable<string> Scopes { get; set; } + + public InteractionType Interaction { get; set; } + + public Dictionary<string, object> AdditionalRequestParameters { get; set; } + } + } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs index 2ff49351c5..a5ba57a5f2 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs @@ -53,5 +53,8 @@ public partial class RemoteAuthenticatorViewCore<TAuthenticationState> where TAu [LoggerMessage(15, LogLevel.Debug, "Logout redirect completed successfully.", EventName = nameof(LogoutRedirectCompletedSuccessfully))] public static partial void LogoutRedirectCompletedSuccessfully(ILogger logger); + + [LoggerMessage(16, LogLevel.Debug, "Login request '{Request}'.", EventName = nameof(LoginRequest))] + public static partial void LoginRequest(ILogger logger, string request); } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs index 1f2d5788e8..9273981076 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs @@ -210,6 +210,7 @@ public partial class RemoteAuthenticatorViewCore<[DynamicallyAccessedMembers(Jso private async Task ProcessLogIn(string returnUrl) { + Log.LoginRequest(Logger, Navigation.HistoryEntryState); AuthenticationState.ReturnUrl = returnUrl; var interactiveRequest = GetCachedNavigationState(); var result = await AuthenticationService.SignInAsync(new RemoteAuthenticationContext<TAuthenticationState> |