Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Bad error when booting webhost without calling UseStartup or Configure #1137

Closed
davidfowl opened this issue Jul 8, 2017 · 24 comments
Closed
Assignees

Comments

@davidfowl
Copy link
Member

Unhandled Exception: System.ArgumentException: A valid non-empty application name must be provided.
Parameter name: applicationName
   at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at ConsoleApp11.Program.Main(String[] args) in C:\Users\dfowler\documents\visual studio 2017\Projects\ConsoleApp11\ConsoleApp11\Program.cs:line 11
@moozzyk
Copy link
Contributor

moozzyk commented Jul 11, 2017

Just hit this in testing. The error message is really misleading.

[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8776789]       System.AggregateException : One or more errors occurred. (A valid non-empty application name must be provided.
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8778140]       Parameter name: applicationName) (The following constructor parameters did not have matching fixture data: ServerFixture serverFixture)
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8779372]       ---- System.ArgumentException : A valid non-empty application name must be provided.
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8780382]       Parameter name: applicationName
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8781072]       ---- The following constructor parameters did not have matching fixture data: ServerFixture serverFixture
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8799203]       Stack Trace:
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8824001]         
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8826139]         ----- Inner Stack Trace #1 (System.ArgumentException) -----
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8828104]            at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8829407]            at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8830773]            at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8831554]            at Microsoft.AspNetCore.SignalR.Tests.Common.ServerFixture.StartServer()
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8832500]            at Microsoft.AspNetCore.SignalR.Tests.Common.ServerFixture..ctor()
[7/11/2017 9:31:34 AM Informational] [xUnit.net 00:00:00.8833458]         ----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----

@moozzyk
Copy link
Contributor

moozzyk commented Jul 12, 2017

You will also get this exception when UseStartup is called from a HostingStartup assembly: #1140

@muratg muratg added this to the 2.1.0 milestone Aug 8, 2017
@CheloXL
Copy link

CheloXL commented Aug 17, 2017

I just upgraded my application to netcore2/mvc core2 and can't run it anymore.
I'm injecting the IStartup using ConfigureServices in WebHostBuilder and I'm getting the above error.

Is there any ETA on this? Or there is another way to bypass this error?

@davidfowl
Copy link
Member Author

davidfowl commented Aug 17, 2017

@CheloXL can you provide repro steps on a new project that show the behavior you're seeing? The issue above is solely about the error message, it has nothing to do with functionality. The behavior should be the same as 1.1.x with respect to adding an IStartup manually.

@CheloXL
Copy link

CheloXL commented Aug 18, 2017

@davidfowl I will try to create one based on the project that I just upgrade. If I'm able to reproduce in a minimal test case, how do you want me to send the files?

@JunTaoLuo
Copy link
Contributor

Would you be able to share it as a git repo?

@davidfowl
Copy link
Member Author

@CheloXL the issue you're likely hitting is the fact that you have to manually set the application name if you add IStartup to the container manually.

@CheloXL
Copy link

CheloXL commented Aug 18, 2017

@davidfowl ok, so, two things:

  1. How do I do that?
  2. Why on 1.1 I don't have to do so?

@JunTaoLuo yes, I already created a test case. But if @davidfowl is right (and I can setup the application name manually and it works), there should be no need for that. Waiting for (1) to try...

@davidfowl
Copy link
Member Author

  1. How do I do that?
.ConfigureServices(services =>
                {
                    services.AddSingleton<IStartup, Startup>();
                })
                .UseSetting(WebHostDefaults.ApplicationKey, typeof(Startup).GetTypeInfo().Assembly.FullName)
  1. Why on 1.1 I don't have to do so?

This is a regression caused by this change ce650ee, we no longer fallback to the entry assembly. @anurse I think we agreed this wouldn't break anyone but it breaks this scenario.

@CheloXL
Copy link

CheloXL commented Aug 18, 2017

@davidfowl Perfect. That worked like a charm. Thanks. I would like this to be documented somewhere. I had to migrate my old authentication code and while that wasn't funny, at least it was well documented.

@davidfowl
Copy link
Member Author

@muratg @Eilon This should be a patch candidate.

@muratg
Copy link

muratg commented Aug 18, 2017

@JunTaoLuo Could you file 1.0.6, 1.1.3 and 2.0.1 bugs to track this as a patch candidate?

@JunTaoLuo
Copy link
Contributor

Patch issues added.

@JunTaoLuo
Copy link
Contributor

@muratg Actually I think this is only a 2.0.1 patch. The original fallback was removed in 2.0.0 only. 1.1.3 and 1.0.6 are not affected.

@muratg muratg modified the milestones: 2.0.1, 2.1.0 Aug 18, 2017
@muratg
Copy link

muratg commented Aug 18, 2017

Thanks @JunTaoLuo. @Eilon, this is a candidate as well.

@JunTaoLuo
Copy link
Contributor

Let's keep this as 2.1.0? I filed the patch candidate for 2.0.1 at #1177

@muratg muratg modified the milestones: 2.1.0, 2.0.1 Aug 18, 2017
@muratg
Copy link

muratg commented Aug 18, 2017

@JunTaoLuo OK sounds good.

@khellang
Copy link
Contributor

This is a regression caused by this change ce650ee, we no longer fallback to the entry assembly. @anurse I think we agreed this wouldn't break anyone but it breaks this scenario.

@davidfowl The commit you linked even added a test explicitly testing this scenario; ce650ee#diff-83865cc417298cc5d089887c9a0094f9R658

@davidfowl
Copy link
Member Author

Yes, it was never supposed to happen in the common case. Turns out if you add an IStartup to the container directly, those assumptions fall apart.

@analogrelay
Copy link
Contributor

analogrelay commented Aug 21, 2017

Yep, this is the scenario where it requires a change. I remember discussing it at the time, hence the test @khellang referenced. It does look like it didn't get clearly called out in the Announcement though (aspnet/Announcements#237), which was a mistake.

@analogrelay
Copy link
Contributor

analogrelay commented Aug 21, 2017

See #1023

The only way to get in the situation where the "non-empty application name" message occurs when the app would otherwise start is if you manually insert an IStartup into the container. In which case, you should still get this error because we need an application name in order to proceed.

This should have been called out more clearly in the Announcement, which is my bad. I've since updated it to help anyone searching for this issue in the future.

@Eilon
Copy link
Member

Eilon commented Aug 21, 2017

Please email me patch candidates... too hard to track these on GitHub.

@davidfowl
Copy link
Member Author

@Eilon would tags help?

@Eilon
Copy link
Member

Eilon commented Aug 21, 2017

Not really, because even though we have tags, people keep using them incorrectly 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants