diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs index 7cb72971..6b650697 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -15,10 +15,6 @@ public static void Initialize(this IHostingEnvironment hostingEnvironment, strin { throw new ArgumentNullException(nameof(options)); } - if (string.IsNullOrEmpty(applicationName)) - { - throw new ArgumentException("A valid non-empty application name must be provided.", nameof(applicationName)); - } if (string.IsNullOrEmpty(contentRootPath)) { throw new ArgumentException("A valid non-empty content root must be provided.", nameof(contentRootPath)); diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs index 10a7a8ec..2a3e1ce4 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs @@ -25,7 +25,7 @@ public WebHostOptions(IConfiguration configuration) if (string.IsNullOrEmpty(startupAssembly)) { // Fall back to entry assembly name if startup assembly hasn't been set. - startupAssembly = Assembly.GetEntryAssembly().GetName().Name; + startupAssembly = Assembly.GetEntryAssembly()?.GetName().Name; } var applicationName = configuration[WebHostDefaults.ApplicationKey]; diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs index f484f57d..5c6a668b 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs @@ -632,7 +632,7 @@ public void DefaultApplicationNameWithInjectedIStartup() .Build()) { var hostingEnv = host.Services.GetService(); - Assert.Equal(Assembly.GetEntryAssembly().GetName().Name, hostingEnv.ApplicationName); + Assert.Equal(Assembly.GetEntryAssembly()?.GetName().Name, hostingEnv.ApplicationName); } }