Wednesday, June 28, 2017

Troubleshooting ASP.NET Core startup error

By Steve Endow

This morning I deployed a new release of an ASP.NET Core API for Dynamics GP.  I've released 3 versions previously, so I expected that this fourth release would be pretty straightforward.  But alas, when we tried to access the new version of the web site, we saw this error message.


"An error occurred while starting the application."

Unfortunately, this error doesn't provide any useful information, and I didn't have developer debug logging enabled in the site code.

Because the site wasn't starting up, my application logging wasn't yet loaded or able to log any errors.  So we had no application log files to work with.

And because of the way that ASP.NET Core web sites work (when using the Kestrel server), IIS logs provide no information--they just showed that we had tried to access the web site URL, with no additional information about the error that was occurring.

After some digging, I found that this is a fairly common issue, and that there is a method of having Kestrel write its own web server logs.  To enable this logging, I edited the web.config file.


I changed stdoutLogEnabled to true, and then verified the location where I wanted the log files to be written.

Once you make that change, you shouldn't need to restart IIS--it looks like Kestrel detects the changes and restarts automatically.  You can then access your site and a log file should be created.


I was then able to open the new log file and see what was causing my site to fail to load.


And the error made sense.  In my latest release, I had added the DataProtection library to my API to provide encryption and decryption, and it was logging this error.

Access to the path 'C:\Windows\system32\config\systemprofile\AppData\Local\ASP.NET\DataProtection-Keys' is denied.

After researching this error and a few others, I discovered that the DataProtection library can be a hassle to deploy, so I removed it and used another encryption class that I have used in the past.

After making that change, the site started working again.

Steve Endow is a Microsoft MVP in Los Angeles.  He is the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

You can also find him on Twitter, YouTube, and Google+



No comments:

Post a Comment