Skip to content

Commit 4af283a

Browse files
authored
Fix behavioral regression in Mvc.Testing (#34449)
1 parent 8e078f5 commit 4af283a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,16 @@ private void SetContentRoot(IWebHostBuilder builder)
225225
}
226226
}
227227

228-
private static string GetContentRootFromFile(string file)
228+
private static string? GetContentRootFromFile(string file)
229229
{
230230
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(File.ReadAllBytes(file))!;
231231
var key = typeof(TEntryPoint).Assembly.GetName().FullName;
232232

233+
// If the `ContentRoot` is not provided in the app manifest, then return null
234+
// and fallback to setting the content root relative to the entrypoint's assembly.
233235
if (!data.TryGetValue(key, out var contentRoot))
234236
{
235-
throw new KeyNotFoundException($"Could not find content root for project '{key}' in test manifest file '{file}'");
237+
return null;
236238
}
237239

238240
return (contentRoot == "~") ? AppContext.BaseDirectory : contentRoot;

0 commit comments

Comments
 (0)