Troubleshooting StackOverflow Exceptions

Is your .NET application randomly crashing? In Production? Without any relevant application logs?  You may be hitting a StackOverflowException if you see exception code 0xc00000fd in the event log. Here’s how to start troubleshooting StackOverflow Exceptions.


First take a look in your event log.  If you see a log similar to this:

Faulting application name: MyApp.exe, version:, time stamp: 0xdfd8c80b
Faulting module name: clr.dll, version: 4.7.2558.0, time stamp: 0x59d413ce
Exception code: 0xc00000fd

The important part here is the exception code 0xc00000fd is a StackOverflowException.

Troubleshooting a .NET StackOverflowException

First thing I would recommend is looking for any recursion in your codebase.  This is often likely the cause when you have unbounded recursion.  It may not be obvious if you have data structures that play a role in your application and specifically where recursion exists.

Debug Diagnostics Tool (DEBUGDIAG)

If you can’t determine where the StackOverflowException is occuring, first place to start is by downloading and installing the Debug Diagnostics Tool from Microsoft.

Once installed, run the “DebugDaig 2 Collection” application.  You will be immediately prompted with the following window:

If you’re running ASP.NET 4.x you will likely be selecting IIS, select the first option.  Otherwise, you likely are going to select a process or a NT Service (Windows Service).

On the follow window, click the Exceptions button.


From here we can specify to capture a StackOverflow exception.  Change the Action Type to a Full userdump.


Finally, click OK and Next to save the new Crash Rule.

Once your application hits a StackOverflowException and crashes, you will have a .dmp file in the rule folder.



Once you have your memory dmp file, we are going to want to open it up with WinDbg.

You have a couple options for installing.  You can download Windows Driver Kit (WDK) which which require you to have latest Visual Studio with Desktop Development with C++ component installed.

Another option is to download the the new WinDbg Preview from the Windows Store.  This is a new version of WinDbg with a more modern look.

Once you have WinDbg, whatever version, you can now type in .loadby sos clr in the Command input.


Followed by !CLRStack as the next command, which should then provide you with your .NET call stack.


If you have any recommendations on WinDbg usage or other useful insights, please share them in the comments or on Twitter.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Zero Downtime Deployments with Octopus Deploy

Zero Downtime DeploymentsIf you’re using Octopus Deploy and AWS with their Elastic Load Balancer (v2) in front of EC2 instances that either self host or sit behind IIS, you can setup zero downtime deployments fairly easily.

Although this blog post will focus on AWS ELB, the same strategy can be applied to Azure.

Rolling Deployments

First is to configure your process that deploys your web application within Octopus.  Octopus has the ability to perform the rolling deployments pattern:

Rolling deployments are a pattern whereby, instead of deploying a package to all servers at once, we slowly roll out the release by deploying it to each server one-by-one.

You can configure rolling deployments per individual process.  Go into the individual process and configure the execution plan to be a rolling deployment.

Rolling Deployments


Since you you have your web application in front of an AWS Elastic Load Balancer, you can add chid steps to the primary step above which will:

  1. Remove the EC2 instance from the ELB Target Group
  2. Perform the upgrade of your web application to the EC2 instance
  3. Re-register the EC2 instance with the ELB Target Group.

When the EC2 instance is removed/deregistered from the ELB Target Group, it will drain all connections.  Meaning it will wait for the current connections to finish before removing it self from the Target Group.

There is an existing template task that you can use in the Octopus Deploy Library to de/reregister your EC2 instances.

Simply add install the task template.  Add a child ask before which will remove and a child task after software upgrade to re-register.


Zero Downtime Deployments

How are you handling zero download deployments?

Are you using containers? Azure? I’d love to hear how in the comments or on Twitter.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

State Driven UI in ASP.NET Core MVC

State Driven UI in ASP.NET Core MVCIn most MVC applications when rending Razor Views, I think the tendency is to use the IUrHelperl.Action inside if anchor href or form action.  If you are using ASP.NET Core, maybe you are using tag helpers like anchor tag helper.  But there’s another option I don’t see very often, which is creating the relevant routes and define them in your ViewModel within in your controller action.   This can be really useful when you’re application’s available actions are driven by state.


Here’s a small example of a shopping cart.  The view model has a list of products that are in your shopping cart.  Something obvious would have the product title be a link to the actual product page.  As mentioned you could do this using the UrlHelper or a tag heper.

Conditional Actions

But how do we handle if there are conditional actions on our page.  For example, there are certain products that you can only purchase a maximum of 1 per cart.  You cannot change the quantity.

If we are using our method above, we also likely need to include something in the view model to indicate if the action is possible.  If it is not, we likely don’t want to render that relevant part of the page.


Instead, an alternative is to generate any links/actions and supply them in your view model.

Now in our razor, we can make the conditional on if the action exists.


If you generate view models that contain links and routes to actions, and are used in your Razor, what’s stopping you from taking that same view model and serializing it and returning JSON.   The ability to add content negotiation and render HTML (via razor) or JSON (direct or more transformation) depending on the clients Accept header.

This is a simple example.  but if you have a lot of UI that’s visibility is driven by state, then this is a great approach.  Ultimately if you are also creating HTTP API’s, this should be a lead down the road to hypermedia.

Do you have any questions or comments? Are you using a similar approach?  I’d love to hear about it in the comments or on Twitter.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.