41

I have an ASP.NET 5 solution with a website and several project libraries. I'm using MVC 6 and Entity Framework 7. Locally the app is working fine and until today it was working also on Azure deployed as an Azure Website.

But today after the latest deployment on Azure I got an error 500 like this on the startup (still working fine locally):

enter image description here

I tried to get more details by :

  • using middleware diagnostics
  • adding the customError / httpError settings in the web.config file
  • downloading the DetailedError page generated

It seems that the error/exception is happening during the Startup/Configure step but I'm still getting the generic error page without details. Even the version generated on the server (DetailedErrors folder) I got this:

enter image description here

I enabled the Failed Request Tracing but still no useful information:

enter image description here

Even if I strip down the code in the Startup/Configure and add a try/catch as suggested I got the same error without détails. It seems to be a configuration/compilation issue but hard to debug without any information.

1
  • 1
    Any news on this in beta 5? Commented Aug 12, 2015 at 23:29

10 Answers 10

22

Errors that occur in startup in an ASPNET5 application are really hard to track down when running the app in Azure (at least with beta 3). Hopefully they find a way to improve the experience. I had to resort to stripping my startup down to the bare bones and then adding code line by line until the failure happened (in my case, it was a missing environment variable).

I've also used code like this (for debugging only) which might help depending on where the error is happening:

public void Configure(IApplicationBuilder app, IHostingEnvironment env )
    {           
        try
        {                       
            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}"
                   );
            });
        }

//exceptions in startup are really bad when running in azure, all you will get is an internal server error
//this code will write the exception message to the browser instead.  Only use for debugging!!!

      catch (Exception ex)          
      {
            app.Run(async context =>
            {
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync(ex.Message);
            });
        }
    }

Update 10/27/2016 A lot has changed since my original answer. The latest guidance is posted here:

https://docs.asp.net/en/latest/fundamentals/hosting.html

So, add:

.CaptureStartupErrors(true) and .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") on your WebHostBuilder like so:

 var host = new WebHostBuilder()
            .CaptureStartupErrors(true)
            .UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
7
  • 1
    Thanks Nelson, that's what I was going to do after all the "classic" debug solutions are exhausted. I'm going to wait if anyone from MSFT can answer the question.
    – MatthieuGD
    Commented Apr 8, 2015 at 20:03
  • 1
    I tried to remove all the code and use the try/catch but no luck yet :( it's kind of frustrating to not be able to see any details
    – MatthieuGD
    Commented Apr 9, 2015 at 12:44
  • 2
    I also had a missing environment variable. Just note that adding the key to the azure configuration table was not enough, I also needed to add the value as well. This was with a clientId and clientSecret. Commented Aug 18, 2015 at 3:16
  • This doesn't appear to work any longer. Instead the exception is completely swallowed, and control is transferred to my MVC controller. (Which doesn't work that well because Configure() failed.)
    – MEMark
    Commented Oct 25, 2016 at 21:36
  • Thanks for updating this! I got lost trying to figure everything out in startup.cs and didn't even think about what I could do with the host. Makes so much sense if you stop long enough to think.
    – Justin_H
    Commented Jan 31, 2017 at 23:51
21

In RC1 (as of beta8, perhaps), one should apparently use:

app.UseDeveloperExceptionPage();

.. which apparently only works if app.Properties["host.AppMode"] is "development".

But this didn't work for me. The error message I was getting was specifically "An error occurred while starting the application", I have found that none of the given configurations will resolve this because the error is occurring before the configurations execute.

Somehow, the publish target folder must have gotten corrupted during publish because I found that deleting the entire deployment directory and re-publishing resolved the problem.

Otherwise, here is the reference: http://docs.asp.net/en/latest/fundamentals/diagnostics.html https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling

5
  • 5
    I was having the same issues with errors not appearing. I published removing existing files and it seems like it worked for me, I must've had a similar issue. For others, If you're publishing from Visual Studio, then tick the "Remove additional files at destination".
    – Yodacheese
    Commented Dec 20, 2015 at 23:59
  • 4
    How exactly do you delete the entire deployment directory on an Azure Website? I know how to do it on a Cloud Service, but can't find a way on an Azure Website.
    – Josh Mouch
    Commented Jan 19, 2016 at 15:25
  • 3
    @Yodacheese's recommendation is what did the trick for me. And Josh I thought maybe doing this through the server explorer (in VS) would work, but turns out you cannot delete anything for this panel. But after attempting to delete all files on publish twice I was able to resolve the exact issue above.
    – Markus
    Commented Mar 4, 2016 at 17:10
  • 1
    Is this really the only way to get decent error messages on Azure in asp.net 5? I can't seem to get any decent error information out of any of the logs, even though my application error is actually happening after my app is loaded.
    – Ed Spencer
    Commented Apr 19, 2016 at 13:43
  • 1
    @JoshMouch go to AppServices > (select your WebApp) > All Settings > Deployment Slots > (select your deployment slot) > Delete
    – themenace
    Commented May 20, 2016 at 11:03
9

You must set app settings property ASPNET_DETAILED_ERRORS to true in web.config file.

Example of my edited web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="bootstrapper-version" value="1.0.0-beta6" />
    <add key="runtime-path" value="..\approot\runtimes" />
    <add key="dnx-version" value="1.0.0-beta6" />
    <add key="dnx-clr" value="clr" />
    <add key="dnx-app-base" value="..\approot\src\MyApp" />
    <!-- This will turn on detailed errors when deployed to remote servers -->
    <!-- This setting is not recommended for production -->
    <add key="ASPNET_DETAILED_ERRORS" value="true" />
  </appSettings>
  <system.web>
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
</configuration>
2
  • 2
    does this still work in beta-8 ? Modified the web.config in the wwwroot that gets published, but no extra info the eventlog or detailed errors. Commented Nov 13, 2015 at 18:56
  • 1
    its because the setting name is ASPNETCORE_DETAILEDERRORS. Reference: learn.microsoft.com/en-us/aspnet/core/fundamentals/host/…. But this is for ASP.NET Core, whereas the question is for ASP.NET
    – Vladislav
    Commented Jul 24, 2020 at 9:48
8

I've experienced the exact same error with a web app running dnx-clr-win-x64.1.0.0-rc1-update1. I did the deployment directly from Visual Studio 2015 Enterprise Update 1. I found that the site was working whenever I did the first deployment on a newly created web app. Starting with the second deployment (even when deploying the exact same content), I started to see Internal Server Error 500. That brought me to the following solution:

Enabling "Remove additional files at destination" in the publishing wizard of Visual Studio fixed it for me.

enter image description here

1
  • 1
    Surprisingly, out of all of these solutions, this one worked for me (running ASP.NET 5 RC1 / Core 1.0 RC1).
    – qJake
    Commented Mar 2, 2016 at 15:01
5

I had the same issue and spent a lot of time trying to dig into error logs, etc. (all of the other solutions given above). None of them giving any clue of what's gone wrong.

What I did that helped me finally see the error was to simply try to publish to a local IIS (after all azure web-app runs your dnx on IIS internally).

I could then immediately see that there are error when IIS tries to compile the source. (in my case was some malformed nuget package).

So in short:

Recreate what happens on azure web-app by publishing to local IIS.

4

Create a web.config inside your wwwroot folder with this content :

<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
</configuration>
3
  • 2
    already did and it doesn't work. The error page is from the new asp.net stack and when I activated the custom error like you suggested I only got the error page in the second screenshot which is not very helpful either.
    – MatthieuGD
    Commented Apr 9, 2015 at 17:31
  • 1
    Remove request tracing and diagnostics middleware and try again. You should see the normal iis error ysod. Commented Apr 9, 2015 at 20:49
  • 1
    Apprently this works only if the error occurs during application startup (ASP.NET 5 RC1). See here: docs.asp.net/en/latest/fundamentals/…
    – Costo
    Commented Dec 18, 2015 at 13:48
3

Have you checked in the eventlog.xml file? It's in the D:\home\LogFiles directory. You can view it from your app's Kudu site, or use the Azure Websites Event Viewer extension.

3
  • 1
    yes I looked into it, and there's nothing logged there. I even look at the log files generated in the subfolder W3SVCXXXX but nothing interesting :(
    – MatthieuGD
    Commented Apr 8, 2015 at 17:18
  • 1
    Hmm, I've had this before (ended up being a problem with my web.config) and I thought that's where I found the info. The only other thing I can think of is enabling Failed Request Tracing and digging through that.
    – BenV
    Commented Apr 8, 2015 at 17:28
  • 1
    actually I don't have any web.config in my project (I don't need it yet, using the config.json method for now). There's one in the azure websites but it's generated during the deployment by kudu. Anyway I'm going to look at the Failed Request Tracing way
    – MatthieuGD
    Commented Apr 8, 2015 at 17:39
3

Did you try using Remote Debugging the Azure Webapp ? Chances are there is some exception happening which is responsible for this and if you watch your DEBUG OUTPUT window, you may be able to see which exception is happening and then change Visual Studio settings to break on that exception to see where it is happening. check this article to understand how to remote debug - http://blogs.msdn.com/b/webdev/archive/2013/11/05/remote-debugging-a-window-azure-web-site-with-visual-studio-2013.aspx

2
  • 1
    Yes already tried but the error is happening too soon I think.
    – MatthieuGD
    Commented Apr 13, 2015 at 11:05
  • 1
    Is it possible to share a sample app where you see this. I can try setting it up and see if I reach somewhere... You can share the sample through OneDrive or any other way if you can Commented Apr 14, 2015 at 16:58
1

In my case with beta5, custom errors in web.config didn't help, local IIS was fine, and adding an exception handler didn't display anything. The only thing that worked was to nuke approot and redeploy.

0

In the Web app's Application settings, in the section App settings, add (or change the value of) Hosting:Environment to Development. Then you get the same error page as in your local development. In my Startup.cs, I have the regular Configure() method with the following code: (still in MVC 1.0 RC1-final)

        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else

Hope this helps!

Not the answer you're looking for? Browse other questions tagged or ask your own question.