TLDR
A previously working (previous version) pushed to Azure now gives a non-descriptive error 500, but runs without issue on two different local PCs. I'm unable to determine the cause and hoping for some help.
Details
I have an ASP.NET Core Web App that I've been developing. The app runs without issue locally (as well as on another PC where I cloned the project from my private git.)
However, I published to my Azure web app (something I did months ago with a previous version) and now it is failing (this is a newly created web app instance.) I am returned a fairly generic error 500 page when I try to view the app...
I finally checked the log stream after reading this and digging around in the azure portal, and was returned an error page with more info, but still not really anything useful.
Inspired by this SO answer, I switched my environment flag (ASPNETCORE_ENVIRONMENT
) to Development
in the Azure "Application Settings" blade and gave it a shot (so I could see the result.) I was hesitant to do this because my sql connection string is in there and varies depending on environment (dev is local, prod is azure sql) so I was guaranteed an error at some point (when it tries to hit the db.) This gave me a very useful and bizarre error message via app.UseDeveloperExceptionPage()
in the Configure
method...
It is claiming that my appsettings.Development.json
is not present! How on earth did that not make it in the publish push?!
Relevant lines from Startup.cs...
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
} // LINE 41 reported
FTP'ing into the /site/wwwroot I see that the file is not there actually (but the generic and production ones are.) Does VS somehow filter these or set an environment variable for packaging when you select Release or Debug? I didn't see any indication of that in the package/publish log.
So, I switched the environment variable back to 'Production' and restarted the web app from the "Overview" blade (just in case.) Then I moved the app.UseDeveloperExceptionPage
line out of the if (env.IsDevelopment()) {
block (so it is always available.) Build, republish (keeping the "Remove additional files at destination" box checked for the time being, takes longer to delete and then push everything but better safe), and refreshed the page, and I'm back to the generic error 500 message (no additional details) again...
I know that customErrors
is no longer relevant, as evidence by my seeing the result of the UseDeveloperExceptionPage
previously. Additionally, I have "Detailed error messages" enabled...
What on earth am I missing?!
EDIT1: Setting my local dev env flag to "Production" in launchSettings.json
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
...and everything still works fine! Yet still error 500 on Azure!
EDIT2:
I realized why appsettings.Development.json
wasn't getting published, it wasnt in my project.json
's publishInclude
section...
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"appsettings.Production.json",
"web.config"
]
},
...still not clear why, after moving the app.UseDeveloperExceptionPage()
outside of the environment check, I wasn't able to see the developer exception page. But now I realize that there are probably other missing files that aren't getting published (no matter the environment!)