diff --git a/src/Framework/Framework/Compilation/DotHtmlFileInfo.cs b/src/Framework/Framework/Compilation/DotHtmlFileInfo.cs index 157d452568..84e9489e73 100644 --- a/src/Framework/Framework/Compilation/DotHtmlFileInfo.cs +++ b/src/Framework/Framework/Compilation/DotHtmlFileInfo.cs @@ -14,7 +14,7 @@ public sealed class DotHtmlFileInfo public ImmutableArray Warnings { get; internal set; } = ImmutableArray.Empty; /// Gets or sets the virtual path to the view. - public string VirtualPath { get; } + public string? VirtualPath { get; } public string? TagName { get; } public string? Namespace { get; } @@ -25,7 +25,7 @@ public sealed class DotHtmlFileInfo public ImmutableArray? DefaultValues { get; } public bool? HasParameters { get; } - public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray? defaultValues = null, bool? hasParameters = null) + public DotHtmlFileInfo(string? virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray? defaultValues = null, bool? hasParameters = null) { VirtualPath = virtualPath; Status = IsDothtmlFile(virtualPath) ? CompilationState.None : CompilationState.NonCompilable; @@ -40,7 +40,7 @@ public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameS HasParameters = hasParameters; } - private static bool IsDothtmlFile(string virtualPath) + private static bool IsDothtmlFile(string? virtualPath) { return !string.IsNullOrWhiteSpace(virtualPath) && ( diff --git a/src/Framework/Framework/Compilation/Static/StaticViewCompiler.cs b/src/Framework/Framework/Compilation/Static/StaticViewCompiler.cs index c9a4fe7394..7f360100f5 100644 --- a/src/Framework/Framework/Compilation/Static/StaticViewCompiler.cs +++ b/src/Framework/Framework/Compilation/Static/StaticViewCompiler.cs @@ -10,6 +10,7 @@ using DotVVM.Framework.Configuration; using DotVVM.Framework.Hosting; using DotVVM.Framework.Security; +using DotVVM.Framework.Utils; using Microsoft.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -33,7 +34,7 @@ public static ImmutableArray CompileAll( diagnostics.AddRange(CompileNoThrow(configuration, markupControl!)); } - var views = configuration.RouteTable.Select(r => r.VirtualPath).ToImmutableArray(); + var views = configuration.RouteTable.Select(r => r.VirtualPath).WhereNotNull().ToImmutableArray(); foreach(var view in views) { diagnostics.AddRange(CompileNoThrow(configuration, view)); diff --git a/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs b/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs index 0c25033cb8..af8f17b3c3 100644 --- a/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs +++ b/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using DotVVM.Framework.Configuration; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Hosting { @@ -39,7 +40,8 @@ public AggregateMarkupFileLoader() /// public string GetMarkupFileVirtualPath(IDotvvmRequestContext context) { - return context.Route!.VirtualPath; + return context.Route!.VirtualPath + ?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path."); } } } diff --git a/src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs b/src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs index d97d2ce1d9..0a2b443537 100644 --- a/src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs +++ b/src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs @@ -38,7 +38,8 @@ public class DefaultMarkupFileLoader : IMarkupFileLoader /// public string GetMarkupFileVirtualPath(IDotvvmRequestContext context) { - return context.Route!.VirtualPath; + return context.Route!.VirtualPath + ?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path."); } } } diff --git a/src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs b/src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs index c424c37c7a..2a680c0876 100644 --- a/src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs +++ b/src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs @@ -58,7 +58,8 @@ public class EmbeddedMarkupFileLoader : IMarkupFileLoader /// public string GetMarkupFileVirtualPath(IDotvvmRequestContext context) { - return context.Route!.VirtualPath; + return context.Route!.VirtualPath + ?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path."); } } } diff --git a/src/Framework/Framework/Routing/RouteHelper.cs b/src/Framework/Framework/Routing/RouteHelper.cs index efafff4232..78761b036c 100644 --- a/src/Framework/Framework/Routing/RouteHelper.cs +++ b/src/Framework/Framework/Routing/RouteHelper.cs @@ -52,7 +52,7 @@ public static void AssertConfigurationIsValid(this DotvvmConfiguration config) invalidRoutes.Add(new DotvvmConfigurationAssertResult(route, DotvvmConfigurationAssertReason.MissingRouteName)); } - var content = loader.GetMarkup(config, route.VirtualPath); + var content = loader.GetMarkup(config, route.VirtualPath!); if (content == null) { invalidRoutes.Add(new DotvvmConfigurationAssertResult(route, DotvvmConfigurationAssertReason.MissingFile));