Share via


Look at Sharing Common Assemblies in ASP.NET 4.5

In this blog, we will look into sharing common assemblies in ASP.NET 4.5 Developer Preview. This feature needs VS 11 SDK & .NET Framework 4.0 latest update. Normally, multiple sites use to have its own copy of same assemblies from a starter kit like AjaxToolkit in its Bin directory. These assemblies are identical in object code & functionality but differ in physical path. Due to this, each assembly has to be read separately during cold startup of the site and kept separately in memory. This will lead to have multiple copies of same assembly consuming RAM and performance hit to load the assembly.  The new interning feature will resolve it by keeping a single copy of that assembly in the file system, and individual assemblies in the site Bin folders are replaced with symbolic links to the single copy. If an individual site needs a distinct version of the assembly, the symbolic link is replaced by the new version of the assembly, and only that site is affected. VS 11 provide a new tool called as aspnet_intern.exe for sharing assemblies using symbolic links. This tool lets you create and manage the store of interned assemblies.

Let’s have a look at it with a live example. Open your VS 11 and create a simple class library Testlib with the below code:

Build it and then create three new web applications with name as MyApp1, MyApp2 & MyApp3 with a reference to Testlib as shown below:

Then, run each web application. Now, open command prompt and point to VS 11 SDK [similar to C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools] and run below command to intern the common assemblies present under ASP.NET Temporary Files folder to CommonAssemblies folder [in our case it’s testlib]:

aspnet_intern -mode exec -sourcedir "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" -interndir C:\CommonAssemblies

By doing this, we can have only one copy of the assembly in RAM for use by multiple sites.  An assembly will be interned, if it was found in more than 3 different locations by default. We can change this value by using minrefcount switch.

We can get detail report [verbose] without interning the assemblies by running below command:

aspnet_intern -mode analyze -sourcedir C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" -interndir C:\ASPNETCommonAssemblies  -v

For more options on this tool, run aspnet_intern /?

We can make sure all eligible assemblies have been interned by running aspnet_intern.exe periodically using a scheduled task.

Note: This blog is based on features of preview only, and is subject to change in later releases.