diff --git a/src/Microsoft.AspNetCore.Mvc.Testing/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Mvc.Testing/Properties/Resources.Designer.cs
index cd0ce4b518..16f29e1d67 100644
--- a/src/Microsoft.AspNetCore.Mvc.Testing/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Testing/Properties/Resources.Designer.cs
@@ -38,6 +38,20 @@ namespace Microsoft.AspNetCore.Mvc.Testing
internal static string FormatMissingDepsFile(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("MissingDepsFile"), p0, p1);
+ ///
+ /// The provided Type '{0}' does not belong to an assembly with an entry point. A common cause for this error is providing a Type from a class library.
+ ///
+ internal static string InvalidAssemblyEntryPoint
+ {
+ get => GetString("InvalidAssemblyEntryPoint");
+ }
+
+ ///
+ /// The provided Type '{0}' does not belong to an assembly with an entry point. A common cause for this error is providing a Type from a class library.
+ ///
+ internal static string FormatInvalidAssemblyEntryPoint(string p0)
+ => string.Format(CultureInfo.CurrentCulture, GetString("InvalidAssemblyEntryPoint"), p0);
+
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
diff --git a/src/Microsoft.AspNetCore.Mvc.Testing/Resources.resx b/src/Microsoft.AspNetCore.Mvc.Testing/Resources.resx
index 8174cf1f2d..adf4045ebe 100644
--- a/src/Microsoft.AspNetCore.Mvc.Testing/Resources.resx
+++ b/src/Microsoft.AspNetCore.Mvc.Testing/Resources.resx
@@ -117,6 +117,9 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ The provided Type '{0}' does not belong to an assembly with an entry point. A common cause for this error is providing a Type from a class library.
+
No method 'public static {0} CreateWebHostBuilder(string[] args)' found on '{1}'. Alternatively, {2} can be extended and 'protected virtual {0} {3}()' can be overridden to provide your own {0} instance.
diff --git a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
index 356bd56d97..85fcdadba2 100644
--- a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
@@ -251,6 +251,11 @@ namespace Microsoft.AspNetCore.Mvc.Testing
private void EnsureDepsFile()
{
+ if (typeof(TEntryPoint).Assembly.EntryPoint == null)
+ {
+ throw new InvalidOperationException(Resources.FormatInvalidAssemblyEntryPoint(typeof(TEntryPoint).Name));
+ }
+
var depsFileName = $"{typeof(TEntryPoint).Assembly.GetName().Name}.deps.json";
var depsFile = new FileInfo(Path.Combine(AppContext.BaseDirectory, depsFileName));
if (!depsFile.Exists)
diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/TestingInfrastructureTests.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/TestingInfrastructureTests.cs
index afa57b5092..54089a8e59 100644
--- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/TestingInfrastructureTests.cs
+++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/TestingInfrastructureTests.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
@@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.Mvc.Testing.Handlers;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
+using RazorPagesClassLibrary;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
@@ -39,6 +41,15 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal("Test", response);
}
+ [Fact]
+ public void TestingInfrastructure_CreateClientThrowsInvalidOperationForNonEntryPoint()
+ {
+ var factory = new WebApplicationFactory();
+ var ex = Assert.Throws(() => factory.CreateClient());
+ Assert.Equal($"The provided Type '{typeof(RazorPagesClassLibrary.ClassLibraryStartup).Name}' does not belong to an assembly with an entry point. A common cause for this error is providing a Type from a class library.",
+ ex.Message);
+ }
+
[Fact]
public async Task TestingInfrastructure_RedirectHandlerWorksWithPreserveMethod()
{
diff --git a/test/WebSites/RazorPagesClassLibrary/ClassLibraryStartup.cs b/test/WebSites/RazorPagesClassLibrary/ClassLibraryStartup.cs
new file mode 100644
index 0000000000..0009c644a4
--- /dev/null
+++ b/test/WebSites/RazorPagesClassLibrary/ClassLibraryStartup.cs
@@ -0,0 +1,21 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace RazorPagesClassLibrary
+{
+ ///
+ /// Empty Startup for testing a Startup file within a class library
+ ///
+ public class ClassLibraryStartup
+ {
+ public void ConfigureServices(IServiceCollection services)
+ {
+
+ }
+
+ public void Configure(IApplicationBuilder app)
+ {
+
+ }
+ }
+}