diff --git a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs index 4585368b830a..5c2d42fedd24 100644 --- a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs +++ b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs @@ -8,11 +8,11 @@ namespace Microsoft.AspNetCore.Components.Endpoints; internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager { - private const string _enableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException"; + private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException"; - [FeatureSwitchDefinition(_enableThrowNavigationException)] + [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - AppContext.TryGetSwitch(_enableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue; private Func? _onNavigateTo; diff --git a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs index e9c6d470d80d..3c27365169cb 100644 --- a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs +++ b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs @@ -849,9 +849,9 @@ public async Task Rendering_ComponentWithJsInteropThrows() [Theory] [InlineData(true)] [InlineData(false)] - public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponseHasAlreadyStarted(bool expectException) + public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponseHasAlreadyStarted(bool allowException) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: expectException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !allowException); // Arrange var ctx = new DefaultHttpContext(); ctx.Request.Scheme = "http"; @@ -867,7 +867,7 @@ public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponse string redirectUri = "http://localhost/redirect"; // Act - if (expectException) + if (allowException) { var exception = await Assert.ThrowsAsync(async () => await renderer.PrerenderComponentAsync( httpContext, diff --git a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs index ddb5df5b03db..2100ef3a7a16 100644 --- a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs +++ b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs @@ -17,11 +17,11 @@ internal sealed partial class RemoteNavigationManager : NavigationManager, IHost private readonly ILogger _logger; private IJSRuntime _jsRuntime; private bool? _navigationLockStateBeforeJsRuntimeAttached; - private const string _enableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException"; + private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException"; - [FeatureSwitchDefinition(_enableThrowNavigationException)] + [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - AppContext.TryGetSwitch(_enableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue; private Func? _onNavigateTo; public event EventHandler? UnhandledException; diff --git a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs index dd9f2a3a47e8..b99a682a9457 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs @@ -1405,7 +1405,7 @@ public void CanPersistMultiplePrerenderedStateDeclaratively_Auto_PersistsOnWebAs [InlineData(false)] public void NavigatesWithInteractivityByRequestRedirection(bool controlFlowByException) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: controlFlowByException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !controlFlowByException); Navigate($"{ServerPathBase}/routing/ssr-navigate-to"); Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text); Browser.Click(By.Id("redirectButton")); diff --git a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs index e5a438283f84..bbeb1ad4d9bb 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs @@ -72,7 +72,7 @@ public void CanUseServerAuthenticationStateByDefault() [InlineData(false, true)] public void NavigatesWithoutInteractivityByRequestRedirection(bool controlFlowByException, bool isStreaming) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: controlFlowByException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !controlFlowByException); string streaming = isStreaming ? $"streaming-" : ""; Navigate($"{ServerPathBase}/routing/ssr-{streaming}navigate-to"); Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text); diff --git a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor index f08a419ef6f6..f21620148737 100644 --- a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor @@ -107,6 +107,6 @@ public class TestServiceProvider : IServiceProvider { public object GetService(Type serviceType) - => throw new NotImplementedException(); + => null; } } diff --git a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in index 829c12db913c..a7c485d95644 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in @@ -8,6 +8,7 @@ Default BlazorWeb-CSharp.Client `$(AssemblyName.Replace(' ', '_')) + true diff --git a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in index 541be08bd263..22ce06f89047 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in @@ -8,6 +8,7 @@ True BlazorWeb-CSharp `$(AssemblyName.Replace(' ', '_')) + true