If you use .NET Framework 4.6.1 or higher, you may be getting an out-of-memory exception. Microsoft has released the following Knowledge Base article to document the problem and provide a mitigation:

KB3152158 - Out-of-memory exception in a managed application that targets .NET Framework 4.6.1

There are two ways to mitigate this problem:

1. Add a registry entry (this is the method recommended by the Knowledge Base article)

Copy the following lines (everything between the dashes; do not include the dashes) into Notepad:

-----
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"NGenReserveForJumpStubs"=dword:00000005

-----

Save the file to your Desktop as NGenReserveForJumpStubs.reg . To do this successfully, you will have to make sure you change the Save as type to All files (*.*) before entering NGenReserveForJumpStubs.reg as the file name.

Then, double-click the NGenReserveForJumpStubs.reg file on your Desktop, and answer in the affirmative until the keys and values have successfully been added to the Registry. Note: You need Administrative privileges to do this.

Now, restart your computer.

2. Create the system environment variable COMPLUS_NGenReserveForJumpStubs and set its value to 5.

Open the System Control Panel (WinKey+Pause)
Click Advanced System Settings (on the left-hand side)
Click Environment Variables...
Under System Variables, click New...
In Variable name enter: COMPLUS_NGenReserveForJumpStubs
In Variable value enter: 5
Click OK.

Now, restart your computer.

Incidentally, the fact that the Knowledge Base article recommends a registry entry to solve the problem tells me that .NET Framework 4.6.2, which was released in the last week of March 2016, also has this problem.