.Net Core 3.1 Azure App Service startup exception: System.IO.DirectoryNotFoundException
It has been a couple of years since I posted here, time spent developing and testing code rather than writing about it, but this bug brought me back to the blog. As it happens, it has also been a couple of years since I published and tested an Azure App Service, but the last time I did it this did not happen.
The details:
Browser error page: “HTTP Error 500.30 – ANCM In-Process Start Failure”. Occurs at app startup.
Initial event log exception: “System.IO.DirectoryNotFoundException: C:\home\site\wwwroot\node_modules\”.
Full event log trace:
Category: Microsoft.AspNetCore.Hosting.Diagnostics EventId: 6 Application startup exception Exception: System.IO.DirectoryNotFoundException: C:\home\site\wwwroot\node_modules\ at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root) at ICMCore.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in F:\Source\Repos\ICMCore\ICMWeb\ICMCore\Startup.cs:line 360 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app) at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) at DevExpress.Web.Internal.ConfigurationSettings.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder) at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
I am a vision-impaired 70-year-old database and software developer that makes use of visual aids to read things. (Yes, this has something to do with the problem.) Among the aids are reducing the screen resolution when I am working on my 15″ notebook (this would have been easier to spot if I had been using my 27″ monitor), and zooming in where possible or using a screen magnifier.
Microsoft, for whatever reason, in their Azure Portal Application Event Logs viewer, filled much of the window with a fixed-size scrolling event log summary. On my screen, the actual log entries appeared only as a small bar across the bottom. As a result, I failed to notice “in F:\Source\Repos\ICMCore\ICMWeb\ICMCore\Startup.cs:line 360″!
[Edit: the log details were in a decent-sized window after all. What I missed was that there were double scroll bars. I needed to move the outer one to see the entire window-within-the-window.]
I did, however, find this post about a similar situation, though in a docker context. Many thanks! I then searched for “node” in Startup.cs and I found it at, of all places, just after line 360. The code reads
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules")), RequestPath = "/node_modules" });
Surprise, surprise. A year or so ago I added the DevExpress reporting feature to the app, in an effort to eliminate SQL Server Reporting Services and its server, an earlier design decision that long predates my work with this client. Now I used to be quite a fan of SSRS, when I worked in the corporate environment, using it from it’s beginning as a downloaded add-on for SQL Server 2000, but that long predates the cloud, let alone .Net Core. Ironically, SSRS is what connected me with this client when their SSRS server quit mysteriously (it does that sometimes) and I brought it back up for them.
The DevExpress reporting system uses node, and I made appropriate changes to the app as directed, the above being one of them. We are not currently using reporting, however, and I decided to remove it when I started getting this error, except that for some reason it wouldn’t quite go away!
Well, it’s gone now, and now I get to figure out why the database connection is failing. It won’t be too hard to guess.
So the resolution for this problem is to delete the code, not to actually resolve it. Unbelievable…