Roundup #9: Razor Email Templates, AWS Lamba .NET Core 2.1, Contract First API Design with OpenAPI V3

Here are the things that caught my eye this week.  I’d love to hear what you found most interesting this week.  Let me know in the comments or on Twitter.

Walkthrough: Creating an HTML Email Template with Razor and Razor Class Libraries and Rendering it from a .NET Standard Class Library

HTML emails are the absolute worst.  Inlined styles.  Nested tables.  Different apps and platforms render the markup differently.  It’s an absolute train wreck.  However, sending plain text emails isn’t a great way to impress your users and often makes emails look fake or like spam.  So fine, HTML emails.  Let’s do it.

Link: https://scottsauber.com/2018/07/07/walkthrough-creating-an-html-email-template-with-razor-and-razor-class-libraries-and-rendering-it-from-a-net-standard-class-library/

 

AWS Lambda Supports .NET Core 2.1

You can now develop your AWS Lambda function code in C# using the .NET Core 2.1 runtime which will soon be the Long Term Support (LTS) version of .NET Core.

Link: https://aws.amazon.com/about-aws/whats-new/2018/06/lambda-supports-dotnetcore-twopointone/

 

Contract First API Design with OpenAPI V3 – Darrel Miller

The Swagger specification is all grown up with it’s new enterprisey name, OpenAPI and there’s a whole set of new features in V3, like links and callbacks. This session will explore what’s new in OpenAPI V3 while designing and building an HTTP API.

Most Swagger/OpenAPI users started by generating their OpenAPI from an API implementation. As developers gain experience, many start to change their approach to start with an OpenAPI description and build an implementation from that. We will compare the approaches and talk about the advantages of Contract First with OpenAPI.

Link: https://www.youtube.com/watch?v=GtTiIY51kK0

 

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

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.

0xc00000fd

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

Faulting application name: MyApp.exe, version: 1.0.0.0, 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.

https://www.microsoft.com/en-us/download/details.aspx?id=49924

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.

DebugDiag

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

DebugDiag

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.

DebugDiag

WinDbg

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.

https://go.microsoft.com/fwlink/?linkid=873060

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.

WinDbg

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

WinDbg

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

AWS ELB

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.

AWS ELB

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.