From b7011ae4f076829e21b22633f1f22236f52c94f8 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Fri, 16 Jul 2021 20:08:27 -0700 Subject: [PATCH] Fix behavioral regression in Mvc.Testing --- src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs index c00809c9ea90..3cd85001d108 100644 --- a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs +++ b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs @@ -225,14 +225,16 @@ private void SetContentRoot(IWebHostBuilder builder) } } - private static string GetContentRootFromFile(string file) + private static string? GetContentRootFromFile(string file) { var data = JsonSerializer.Deserialize>(File.ReadAllBytes(file))!; var key = typeof(TEntryPoint).Assembly.GetName().FullName; + // If the `ContentRoot` is not provided in the app manifest, then return null + // and fallback to setting the content root relative to the entrypoint's assembly. if (!data.TryGetValue(key, out var contentRoot)) { - throw new KeyNotFoundException($"Could not find content root for project '{key}' in test manifest file '{file}'"); + return null; } return (contentRoot == "~") ? AppContext.BaseDirectory : contentRoot;