Click here to Skip to main content
13,139,569 members (51,234 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 3 Aug 2006

The NAR loader - single file .NET deployment

, 27 Oct 2006
Rate this:
Please Sign up or sign in to vote.
JAR archives for .NET = NAR archives.

Sample application inside NAR archive


Maybe, some of you know the concept of JAR archives from Java. A lot of things from Java have found their way to the .NET world. Having the same functionality for .NET would be a nice feature. Since .NET 2, Microsoft has included some very interesting features in the CLR and the framework. These features make it possible to create the functionality needed to handle archives for .NET - called NAR archives. NAR archives are ordinary ZIP files containing an (optional) XML manifest file - which informs the loader about what to load, and all application contents like the app.config file and the assemblies. The loader for these archives works only with .NET 2.x. .NET 1.x is not supported.

So today, we have XCOPY deployment of .NET applications, but tomorrow, we might have single file copy deployment for .NET applications.


The CLR as the heart of .NET is a standard Windows component, and as such, it can be used by other (unmanaged) Windows applications to extend them with .NET functionality. This is also true for .NET 1.x. But since .NET 2.0, you can customize a lot more things when using the CLR. From telling the CLR from where to load assemblies (that's one thing that's used by the NAR loader), to how the GC should behave, or what to do with policies. By hosting the CLR in an application, you can extend it, but unfortunately, the way to achieve this is not always as straightforward as it could be. Especially, security can be tricky. The loader creates its own CAS group during installation. You can examine this group with the Microsoft .NET Framework 2.0 Configuration Control Panel applet (Control Panel/Administrative Tools/Microsoft .NET Framework 2.0 Configuration).

Using the code

The NAR loader consists of three parts:

  1. The unmanaged VC++ host for the CLR.

    The host is responsible for preparing the right conditions for the following managed part. It ensures that security is in place, configures the CLR, provides the assemblies of the NAR archive to the CLR, and after the application inside the NAR archives terminates, cleans up everything. This part also registers the file extension .nar with the NAR loader so that a double-click is enough to start applications from inside NAR archives.

  2. The managed C# domain manager.

    The assembly of the managed domain manager is included as a resource in the unmanaged host part of the loader. After the unmanaged part has finished initialization and setup, the assembly is extracted from the resource and loaded into the CLR. This is done in memory without extracting it to the disk first!

  3. A sample NAR archive with a test application which tests most aspects of .NET applications like satellite assemblies, private search paths, multi module assemblies etc.

    You will find Debug and Release builds zipped in the bin directory. Building the loader from source builds all three parts. A build should normally work without problems, but if it fails, it's likely that one of the custom build steps needs customization (Projects: NARTestModule, NARTest, NARLoaderManager, NARLoaderMain, and the file NARLoader.h in NARLoaderMain).

New features

This version of the loader is now capable of creating self running archives, including the possibility to use custom icons for the resulting .exe file. Now, you can pack your application's assemblies into one single .exe file and deploy this. Password protected, strong AES encrypted archives are now also possible. Use this feature to either obfuscate your applications assemblies and/or to control application usage.

If your archive contains a zip comment this can be displayed at application startup. It can be used to display license agreements or other information.

Points of interest

Hosting the CLR is a great way to extend unmanaged applications, but it is also an opportunity to extend the .NET environment itself. Using the CLR hosting interfaces is (most of the time) straightforward, but sometimes the available documentation on MSDN lacks some clarifying hints. During development, fuslogvw.exe was a valuable tool for debugging. By using NAR archives, application deployment can be simplified.

A full manual and further information about the NAR loader can be found at the NAR loader project website.


The latest stable version is 1.2 as of 26 October 2006.

Current version

1.22006.10.26Adds support for strong AES encrypted, password protected archives and archive comments

Older versions

1.12006.08.17Adds support for self-running archives including custom icons
1.0a2006.08.03Allows install and uninstall of loader CAS code group, and .nar file extension handling.
1.02005.03.03First public release - no longer available


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Richard Prinz
Austria Austria
No Biography provided

You may also be interested in...

Comments and Discussions

Generalhost in c# Pin
Unruled Boy7-Jan-09 16:41
memberUnruled Boy7-Jan-09 16:41 
GeneralGreat idea Pin
Alexander Stojakovic12-Feb-07 7:04
memberAlexander Stojakovic12-Feb-07 7:04 
GeneralCOM Pin
Bill Seddon25-Jan-07 22:47
memberBill Seddon25-Jan-07 22:47 
GeneralRe: COM Pin
Richard Prinz26-Jan-07 22:55
memberRichard Prinz26-Jan-07 22:55 
GeneralRe: COM Pin
Bill Seddon26-Jan-07 23:45
memberBill Seddon26-Jan-07 23:45 
GeneralRe: COM Pin
Richard Prinz30-Jan-07 4:41
memberRichard Prinz30-Jan-07 4:41 
GeneralRe: COM Pin
Bill Seddon30-Jan-07 5:09
memberBill Seddon30-Jan-07 5:09 
My thinking at the moment that the the way to try to implement a COM interface will be to copy the mechanism used by the COM Shims generated by the shim wizards. Initially, for me, using a specific interface will work, one that implements a fixed set of known methods just as happens with the add-in shims. In this way a COM interface method can be proxied the corresponding method of the assembly 1:1.

A future implementation can make heavy use of QueryInterface. The loader can be told (via information in the registry just like mscoree) what assembly it is to proxy. The loader can then create the domain (as it does now) load the primary assembly and use reflection to determine the COM interfaces it exposes and build a pseudo v-table for each entry point. The QueryInterface implementation can then return a pointer to the pseudo v-table for each uuid/dispid it recognises and then proxy any call using the pointer to the real, assembly, based method.

However, that's in the future. Right now I'm trying to understand why my NAR will not work. Your NARTest works OK. Stepping through NARLoader.exe I can see that my primary assembly is found, extracted and loaded OK but at the point supporting assmeblies should be loaded the narloadermanager assembly is requested again and then, bang, there's an exception. So I'm trying to work out why the narloadermanager assembly is requested a second time. This behaviour doesn't occur when NARTest is being used. Mmmm.

I was confused initially because the loader would not accept my primary assembly. It turns out the problem is that the GetMethod() in NARLoaderManager::Run() does not expect a public static Main() method and is instead expecting private Main method.

Is there any easy way to watch the NARLoaderManager?


Bill Seddon
GeneralILMerge Pin
reinux27-Oct-06 16:03
memberreinux27-Oct-06 16:03 
GeneralCannot load class by reflection Pin
Barry Kwok21-Aug-06 15:29
memberBarry Kwok21-Aug-06 15:29 
GeneralRe: Cannot load class by reflection Pin
Richard Prinz21-Aug-06 23:10
memberRichard Prinz21-Aug-06 23:10 
GeneralRe: Cannot load class by reflection Pin
Barry Kwok22-Aug-06 15:46
memberBarry Kwok22-Aug-06 15:46 
GeneralRe: Cannot load class by reflection Pin
Richard Prinz22-Aug-06 19:38
memberRichard Prinz22-Aug-06 19:38 
GeneralGreat Help at the right time! Pin
Thomas Krojer18-Aug-06 3:21
memberThomas Krojer18-Aug-06 3:21 
QuestionDoesn't NetZ already do this? Pin
Marc Clifton7-Aug-06 16:21
protectorMarc Clifton7-Aug-06 16:21 
AnswerRe: Doesn't NetZ already do this? Pin
Herman Chelette8-Aug-06 3:08
memberHerman Chelette8-Aug-06 3:08 
GeneralRe: Doesn't NetZ already do this? Pin
Richard Prinz9-Aug-06 3:56
memberRichard Prinz9-Aug-06 3:56 
GeneralRe: Doesn't NetZ already do this? Pin
Herman Chelette9-Aug-06 4:06
memberHerman Chelette9-Aug-06 4:06 
GeneralNice. Pin
kjquinn4-Aug-06 4:22
memberkjquinn4-Aug-06 4:22 
GeneralRe: Nice. Pin
Richard Prinz4-Aug-06 6:27
memberRichard Prinz4-Aug-06 6:27 
GeneralNice idea but.. Pin
FZelle4-Aug-06 2:54
memberFZelle4-Aug-06 2:54 
GeneralRe: Nice idea but.. Pin
Richard Prinz4-Aug-06 6:25
memberRichard Prinz4-Aug-06 6:25 
GeneralRe: Nice idea but.. Pin
FZelle4-Aug-06 8:19
memberFZelle4-Aug-06 8:19 
GeneralRe: Nice idea but.. Pin
Richard Prinz4-Aug-06 9:36
memberRichard Prinz4-Aug-06 9:36 
GeneralRe: Nice idea but.. Pin
FZelle4-Aug-06 9:42
memberFZelle4-Aug-06 9:42 
GeneralNice Pin
2ASoft3-Aug-06 14:11
member2ASoft3-Aug-06 14:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 27 Oct 2006
Article Copyright 2006 by Richard Prinz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid