Mvc: ASP.NET Core 2.0 API return 404 when startup.cs is in different assembly

Created on 14 Dec 2017  路  2Comments  路  Source: aspnet/Mvc

Hi

I have Startup.cs (_DefaultStartup.cs_) in different netstandard2.0 assembly named CoreLib. When I run WebApplication, it instantiates Startup class correctly at runtime but after that, it returns 404 when processing actual HTTP request.

If I move Startup.cs back to WebApplication it works fine.
If I create a new class in WebApplication derived from DefaultStartup.cs and pass it as a startup it works fine. Not sure what is the reason.

Can you please help? I have attached a sample application.

Similar Issue: #5222

WebApplication.zip

question

Most helpful comment

Calling UseStartup resets the config value that drives IHostingEnvironment.ApplicationName. You need to re-order your calls to UseStartup and .UseSetting(WebHostDefaults.ApplicationKey, Assembly.GetEntryAssembly().GetName().Name) in APIActivator. You also need to use Assembly.GetName().Name and not Assembly.FullName as the value for ApplicationKey.

All 2 comments

Calling UseStartup resets the config value that drives IHostingEnvironment.ApplicationName. You need to re-order your calls to UseStartup and .UseSetting(WebHostDefaults.ApplicationKey, Assembly.GetEntryAssembly().GetName().Name) in APIActivator. You also need to use Assembly.GetName().Name and not Assembly.FullName as the value for ApplicationKey.

@pranavkm Thank you so much, Pranav! Really appreciate your help.
It's working now. 馃憤

Was this page helpful?
0 / 5 - 0 ratings