Skip to content

Commit 4fcc0f0

Browse files
authored
Fix linker issues (#45028)
1 parent 5918bc9 commit 4fcc0f0

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<linker>
2+
<assembly fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication">
3+
<type fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationContext`1" preserve="all" />
4+
</assembly>
5+
</linker>

src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040

4141
<Content Remove="$(YarnWorkingDir)**" />
4242
<None Include="$(YarnWorkingDir)*" Exclude="$(YarnWorkingDir)node_modules\**" />
43+
44+
<EmbeddedResource Include="ILLink.Descriptors.xml">
45+
<LogicalName>ILLink.Descriptors.xml</LogicalName>
46+
</EmbeddedResource>
4347

4448
<UpToDateCheckInput Include="@(YarnInputs)" Set="StaticWebassets" />
4549
<UpToDateCheckOutput Include="@(YarnOutputs)" Set="StaticWebassets" />

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication;
1414
[JsonConverter(typeof(Converter))]
1515
public sealed class InteractiveRequestOptions
1616
{
17+
private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions
18+
{
19+
MaxDepth = 32,
20+
PropertyNameCaseInsensitive = true,
21+
};
22+
1723
/// <summary>
1824
/// Gets the request type.
1925
/// </summary>
@@ -86,17 +92,29 @@ public bool TryRemoveAdditionalParameter(string name)
8692
static TValue Deserialize(JsonElement element) => element.Deserialize<TValue>();
8793
}
8894

89-
internal string ToState() => JsonSerializer.Serialize(this, InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions);
90-
91-
internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize(
95+
[UnconditionalSuppressMessage(
96+
"Trimming",
97+
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
98+
Justification = "This method serializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")]
99+
internal string ToState() => JsonSerializer.Serialize(this, SerializerOptions);
100+
101+
[UnconditionalSuppressMessage(
102+
"Trimming",
103+
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
104+
Justification = "This method deserializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")]
105+
internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize<InteractiveRequestOptions>(
92106
state,
93-
InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions);
107+
SerializerOptions);
94108

95109
internal class Converter : JsonConverter<InteractiveRequestOptions>
96110
{
111+
[UnconditionalSuppressMessage(
112+
"Trimming",
113+
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
114+
Justification = "This converter reads 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")]
97115
public override InteractiveRequestOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
98116
{
99-
var requestOptions = JsonSerializer.Deserialize(ref reader, InteractiveRequestOptionsSerializerContext.Default.OptionsRecord);
117+
var requestOptions = JsonSerializer.Deserialize<InteractiveOptions>(ref reader, options);
100118

101119
return new InteractiveRequestOptions
102120
{
@@ -107,26 +125,27 @@ public override InteractiveRequestOptions Read(ref Utf8JsonReader reader, Type t
107125
};
108126
}
109127

128+
[UnconditionalSuppressMessage(
129+
"Trimming",
130+
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
131+
Justification = "This converter writes 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")]
110132
public override void Write(Utf8JsonWriter writer, InteractiveRequestOptions value, JsonSerializerOptions options)
111133
{
112134
JsonSerializer.Serialize(
113135
writer,
114-
new OptionsRecord(value.ReturnUrl, value.Scopes, value.Interaction, value.AdditionalRequestParameters),
115-
InteractiveRequestOptionsSerializerContext.Default.OptionsRecord);
136+
new InteractiveOptions { ReturnUrl = value.ReturnUrl, Scopes = value.Scopes, Interaction = value.Interaction, AdditionalRequestParameters = value.AdditionalRequestParameters },
137+
options);
116138
}
117139

118-
internal record struct OptionsRecord(
119-
[property: JsonInclude] string ReturnUrl,
120-
[property: JsonInclude] IEnumerable<string> Scopes,
121-
[property: JsonInclude] InteractionType Interaction,
122-
[property: JsonInclude] Dictionary<string, object> AdditionalRequestParameters);
123-
}
124-
}
140+
public struct InteractiveOptions
141+
{
142+
public string ReturnUrl { get; set; }
125143

126-
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = false)]
127-
[JsonSerializable(typeof(InteractiveRequestOptions))]
128-
[JsonSerializable(typeof(InteractiveRequestOptions.Converter.OptionsRecord))]
129-
[JsonSerializable(typeof(JsonElement))]
130-
internal partial class InteractiveRequestOptionsSerializerContext : JsonSerializerContext
131-
{
144+
public IEnumerable<string> Scopes { get; set; }
145+
146+
public InteractionType Interaction { get; set; }
147+
148+
public Dictionary<string, object> AdditionalRequestParameters { get; set; }
149+
}
150+
}
132151
}

src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ private static partial class Log
5353

5454
[LoggerMessage(15, LogLevel.Debug, "Logout redirect completed successfully.", EventName = nameof(LogoutRedirectCompletedSuccessfully))]
5555
public static partial void LogoutRedirectCompletedSuccessfully(ILogger logger);
56+
57+
[LoggerMessage(16, LogLevel.Debug, "Login request '{Request}'.", EventName = nameof(LoginRequest))]
58+
public static partial void LoginRequest(ILogger logger, string request);
5659
}
5760
}

src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ protected override async Task OnParametersSetAsync()
210210

211211
private async Task ProcessLogIn(string returnUrl)
212212
{
213+
Log.LoginRequest(Logger, Navigation.HistoryEntryState);
213214
AuthenticationState.ReturnUrl = returnUrl;
214215
var interactiveRequest = GetCachedNavigationState();
215216
var result = await AuthenticationService.SignInAsync(new RemoteAuthenticationContext<TAuthenticationState>

0 commit comments

Comments
 (0)