Microsoft .NET Framework 4.5.1 is an in-place update to .NET Framework 4.0 and the .NET Framework 4.5. This version can be run side-by-side with .NET 3.5 and earlier versions. A couple of new features were introduced in .NET framework 4.5.1, as well as some improvements were implemented in the areas of Application Performance and Debugging applications. Some of them are listed here:
Debugging Feature Improvements
- 64-Bit Edit and Continue support in Visual Studio 2013
- Inspecting Method return value while debugging using Autos Window as well as a pseudo variable $ReturnValue
- ADO.NET Connection Resiliency
- Async Debugging Enhancements
Application Performance Improvements
- ASP.NET Application Suspension
- On-Demand Large-Object heap compaction
- Multi-core JIT Improvements
This article is published from the DotNetCurry .NET Magazine – A Free High Quality Digital Magazine for .NET professionals published once every two months. Subscribe to this eMagazine for Free and get access to hundreds of free .NET tutorials from experts
Debugging Feature Improvements in .NET Framework 4.5.1
64-Bit Edit and Continue support in Visual Studio 2013
The debugging feature Edit and Continue, as our VB 6 developers will recall, was a popular feature which allowed developers to make changes to the code during debugging it. This feature allows user to fix the bugs quickly without restarting the debugging session, which in turn expedites testing of various scenarios.
Versions prior to Visual Studio 2013 provided support for Edit and Continue for 32-bit targeted environment. If you tried Edit and Continue for a 64-bit targeted environment in a version prior to VS 2013, you would receive the following error
In Visual Studio 2013, we now have support for Edit and Continue in 64-bit environments. This feature is by default ON for Windows Application as well as Web Application under Visual Studio 2013. You can cross check the same in the debugging section by going to Tools > Options Menu.
When you use the Edit and Continue with 64-bit targeted environments, you can start editing the code while debugging it, as shown here -
Inspecting Method Return value While Debugging
The next feature improvement which we will talk about is how to inspect a method return value in .NET 4.5.1. In Visual Studio 2013, while debugging, we can now check the return values of a function or of nested functions. The first way of checking return value is to make use of Autos window. Let's see an example of the same -
static void Main(string args)
double result = SalesNetProfit(TotalCostOfGoodsAndServices(), TotalExpenseCost(), TotalSales());
private static double SalesNetProfit(double COGS, double Expense, double ActualSales)
return ActualSales - (COGS + Expense);
private static double TotalCostOfGoodsAndServices()
private static double TotalExpenseCost()
private static double TotalSales()
The above console application calls the SalesNetProfit() in the Main function. The SalesNetProfit function calls other functions to fetch parameter values. When you start debugging the application and execute the SalesNetProfit() function, open the Autos window and see the output. You will see that the return values of functions/nested functions are listed. This is useful when you are not storing the result of a method call in a variable, e.g: when a method is used as a parameter or return value of another method.
Another way of finding the return values of a function is using a new pseudo variable "$ReturnValue". Just type $ReturnValue in the Immediate window (Ctrl + Alt + I) or a Watch window after you have stepped out of the method call. Shown here is the variable in action:
Entity Framework and ADO.NET Connection Resiliency
The Entity Framework and ADO.NET Connection Resiliency introduced in .NET Framework 4.5.1 recreates a broken connection and automatically tries to establish a connection with the database.
Any data centric application is crucial to a business and should be capable of displaying/fetching the data from the remote servers, whenever required. When we design data centric applications, there are a large number of possibilities that needs to be thought of when the connection to the database goes idle/broken.
In such situations, you will have to build your own custom Connection Resiliency feature which will retry establishing broken connections. In .NET Framework 4.5.1, Microsoft has provided EF/ADO.NET Connection Resiliency feature out-of-box. What you have to do is target your application to the use Framework 4.5.1 and this feature will be available to you. No configurations/APIs are needed when you work with this feature. This feature will automatically recreate broken connections and also retry transactions. Pretty cool!
Async Debugging Enhancements
Another feature improvement I want to highlight is Async Debugging Enhancements in Visual Studio 2013. In the .NET world, Async programming has gained momentum when Task Parallel Library (TPL) and keywords like async and await were introduced. For a developer, debugging is an important step during development to check how the code executes, proceeds and if it provides the desired results. We can make use of a Call Stack window for seeing these details.
Let's write a program to test the Async Debugging Enhancements feature using Visual Studio 2013. Here’s a sample screenshot of our program -
The button click event code looks like the following -
private async void button1_Click(object sender, EventArgs e)
var result = await WriteReadFile();
private async Task WriteReadFile()
StreamWriter SW = new StreamWriter(@"E:\test.txt", true);
await SW.WriteLineAsync("WelCome To India");
StreamReader SR = new StreamReader(@"E:\test.txt");
var result=await SR.ReadToEndAsync();
If you debug the application in Visual Studio 2012, you will see a similar output:
The call stack window shows a lot of code which you don't want see as it does not contain any logical starting point. However if you debug the same code in Visual Studio 2013, you will observe that the Call Stack is much more cleaner as shown here -
The Call Stack window in Visual Studio 2013 has hidden External Code. Now we have a neat and a clean view of Call Stack window.
Also take a look at the Task window. It shows you all the active tasks, completed tasks as well as scheduled tasks as shown below -
Application Performance Improvements
ASP.NET App Suspend
In .NET Framework 4.5.1, a new feature called ASP.NET App Suspend has been introduced for hosting an ASP.NET Web site. This feature is introduced in IIS 8.5 and Windows Server 2012 R2.
The basic concept is that all sites are in an inactive mode. When a site is requested, it is loaded into memory, the mode becomes active, and the site responds to page requests. When a site becomes idle (depending on the timeout setting), the site is put in a suspended state and the CPU resources and the memory it was using is made available for requests to other sites. As soon as a request for the site is made, it can be resumed very quickly and respond to traffic again.
This new feature makes effective utilization of your hardware resources and increases the start-up time. To use this feature, you don't have to learn any new API. This feature is a simple configuration of Application Pool. Right click the Application Pool and click on Advance Settings as shown below -
In the Advance Settings window, go to Process Model section and expand the value of "Idle Time-out Action" property value. You will see two values. The default value is set to "Terminate". The other value which is available is "Suspend" as shown here -
By setting the Idle Time-out Action to suspend, when the Idle Time-out occurs, the ASP.NET web site gets suspended from CPU activities. It also gets paged to the disk in a "Ready to Go" state. Hence the start-up time is dramatically increased.
On-Demand Large-Object heap compaction
Another very exciting feature introduced in .NET 4.5.1 is the On-Demand Large Object Heap Compaction. Before the release of .NET Framework 4.5.1, the large object heap compaction was not available. Because of this, fragmentation occurred over a period of time. When you use 32-bit systems, the processes running under them may throw the OutOfMemory exception in case your app is making use of large amount of memory, like large arrays. The On-demand large object heap compaction is now supported in .NET framework 4.5.1 to avoid the OutOfMemory exception. This feature is available as an on-demand feature as it is expensive. The Garbage Collection pause time is more and hence using this feature needs to be decided based on the situation. For example if you are experiencing OutOfMemory exceptions.
You can set this feature using GCSettings which comes under System.Runtime namespace. The GCSetting provides a property LargeObjectHeapCompactionMode that has two values - Default and CompactOnce. The default value is Default which does not compact the Large Object Heap compaction during Garbage collection. If you assign the property a value of CompactOnce, the Large Object Heap is compacted during the next full blocking garbage collection, and the property value is reset to GCLargeObjectHeapCompactionMode.Default
MultiCore JIT Improvements
When you work with large applications, a common concern for developers is how to increase the start-up time of an application. Most of the developers make use of NGen.exe [Native Image Generator] to reduce the start-up time which JIT’s your code at installation and not at start-up time. Now this gives us a flexibility to reduce the start-up time of our applications. However what in cases where we don’t have installation scenarios? In such situations, you will not be able to take advantage of the NGen.exe tool.
MultiCore JT is a performance feature that can use be used to speed up an application launch time by 40-50%. The benefits can be realized both in a Desktop as well as an in an ASP.NET application and server as well as client apps. Multi-core JIT is automatically enabled for ASP.NET apps and is enabled on Assembly.LoadFrom and Appdomain.AssemblyResolve You can read more about it here.
For additional details on .NET 4.5.1 check the official MSDN documentation.
So these were some new features and improvements in the latest release of the .NET Framework. I hope you will make use of them in your .NET apps!
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!