Skip to content

Commit cbfb890

Browse files
[release/7.0] [Blazor] Fix linking issues (#44260)
Backport of #43515 to release/7.0 /cc @MackinnonBuck @javiercn # Fix linking issues Fixes an issue reported by manual testing where Blazor WebAssembly projects created from the Individual Auth template throw an exception on page load after publishing. ## Description The problem was already fixed in `main` by making `RemoteAuthenticationService` more linker friendly. From @javiercn's comment on the original issue: > What was happening was that the linker was erasing the parameter names of the record we were using for serializing the data Fixes https://github.com/aspnet/AspNetCore-ManualTests/issues/1556 ## Customer Impact Customers are likely to encounter this issue, especially since one of our project templates reproduces the bug. It's expected that our project templates should be ready to publish out of the box. ## Regression? - [X] Yes - [ ] No Regressed from .NET 6. ## Risk - [ ] High - [ ] Medium - [X] Low The change only involves minor restructuring to enable linker-friendliness. There are no changes to any core functionality. ## Verification - [X] Manual (required) - [ ] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [X] N/A
1 parent 265991c commit cbfb890

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RemoteAuthenticationService<
3131
{
3232
private static readonly TimeSpan _userCacheRefreshInterval = TimeSpan.FromSeconds(60);
3333
private bool _initialized;
34-
private readonly JavaScriptLoggingOptions _loggingOptions;
34+
private readonly RemoteAuthenticationServiceJavaScriptLoggingOptions _loggingOptions;
3535

3636
// This defaults to 1/1/1970
3737
private DateTimeOffset _userLastCheck = DateTimeOffset.FromUnixTimeSeconds(0);
@@ -93,7 +93,11 @@ public RemoteAuthenticationService(
9393
Navigation = navigation;
9494
AccountClaimsPrincipalFactory = accountClaimsPrincipalFactory;
9595
Options = options.Value;
96-
_loggingOptions = new JavaScriptLoggingOptions(logger?.IsEnabled(LogLevel.Debug) ?? false, logger?.IsEnabled(LogLevel.Trace) ?? false);
96+
_loggingOptions = new RemoteAuthenticationServiceJavaScriptLoggingOptions
97+
{
98+
DebugEnabled = logger?.IsEnabled(LogLevel.Debug) ?? false,
99+
TraceEnabled = logger?.IsEnabled(LogLevel.Trace) ?? false
100+
};
97101
}
98102

99103
/// <inheritdoc />
@@ -163,6 +167,7 @@ public virtual async ValueTask<AccessTokenResult> RequestAccessToken()
163167
/// <inheritdoc />
164168
[DynamicDependency(JsonSerialized, typeof(AccessToken))]
165169
[DynamicDependency(JsonSerialized, typeof(AccessTokenRequestOptions))]
170+
166171
public virtual async ValueTask<AccessTokenResult> RequestAccessToken(AccessTokenRequestOptions options)
167172
{
168173
if (options is null)
@@ -215,6 +220,7 @@ protected internal virtual async ValueTask<ClaimsPrincipal> GetAuthenticatedUser
215220
return user;
216221
}
217222

223+
[DynamicDependency(JsonSerialized, typeof(RemoteAuthenticationServiceJavaScriptLoggingOptions))]
218224
private async ValueTask EnsureAuthService()
219225
{
220226
if (!_initialized)
@@ -240,7 +246,15 @@ private void UpdateUser(Task<ClaimsPrincipal> task)
240246
static async Task<AuthenticationState> UpdateAuthenticationState(Task<ClaimsPrincipal> futureUser) => new AuthenticationState(await futureUser);
241247
}
242248

243-
private record JavaScriptLoggingOptions(bool DebugEnabled, bool TraceEnabled);
249+
}
250+
251+
// We need to do this as it can't be nested inside RemoteAuthenticationService because
252+
// it needs to be put in an attribute for linking purposes and that can't be an open generic type.
253+
internal class RemoteAuthenticationServiceJavaScriptLoggingOptions
254+
{
255+
public bool DebugEnabled { get; set; }
256+
257+
public bool TraceEnabled { get; set; }
244258
}
245259

246260
// Internal for testing purposes

0 commit comments

Comments
 (0)