.NET Fusion Workshop
Home About Workshops Articles Writing Talks Books Contact

.NET Fusion Workshop

This is a self paced workshop designed to lead you through the benefits and features of the .NET Fusion technology.

This Workshop Will Teach You

  • Location of .NET assemblies and how to change the default locations
  • Using .NET tools to resolve problems with assembly locations and how to fix broken applications
  • Sharing assemblies with the GAC, updating GAC dependencies with publisher policy files, GAC references
  • Satellite assemblies and culture specific resources
  • Dynamic loading of assemblies, partial named assemblies
  • Accessing the Fusion API
  • Fusion and the Compact Framework
  • Generating Native Images from .NET Assemblies
  • Native Assemblies

Introduction

Fusion is the .NET technology used to locate and load .NET assemblies. Assemblies are the unit of deployment, security and type definition. Assemblies bridge the current technologies of executable files and future technologies of loading and executing types. In the current versions of .NET assemblies use the established PE (portable executable) file format, however, assemblies extend the format and eschew the established mechanism for exporting executable code (export tables) for a new mechanism called metadata. Furthermore, where DLLs and EXEs are single, standalone files, assemblies can be made up of a collection of files: modules and resource files. Each module is a PE file with a .text section. .NET does not need any other section in the PE file, the .text section contains all of the code, all of the metadata and all the resources embedded in the module. In effect, the PE file format is just a wrapper around a complex .NET structure.

While the internal format of assemblies is a big change, it is not the biggest change. Win32 files can have long names, but these names are not unique between publishers, or between versions of a file from a single publisher. This lack of uniqueness caused the infamous 'DLL Hell' problem. .NET addresses this problem in two ways. First, it changes the way that assemblies are named, by providing names that contain a version element and an element that distinguishes between publishers. Second, .NET does not use System32 to share files. Finally, .NET provides a replacement for LoadLibrary, called Fusion, that is flexible, configurable, and removes any possibilities of loading the wrong file by mistake.

This workshop will lead you through the main features of Fusion step by step. You will learn how to configure Fusion, how to understand Fusion logs and how to use the .NET Fusion tools.

The example code for this workshop can be found here.

Requirements

This workshop was originally written for .NET version 1.1 on Windows XP. When Microsoft released .NET 2.0 I revised the workshop adding annotations for the changes in version 2.0. Since then Microsoft have released 'version 3.0' of the .NET framework. However (with a few minor changes), this is merely version 2.0 distributed with the WinFX library. This means that in most cases .NET 2.0 and .NET 3.0 are interchangeable. In the workshop when I say version 3.0 you can assume that I also mean version 2.0. If I do not mention a version then you should assume that the text refers to all versions of .NET which means 3.0, 2.0, 1.1 and 1.0.

The demonstrations will use the command line tools provided by the .NET SDK and the code will be written in C#. The example code can easily be converted to other .NET languages and can easily be converted to VS.NET projects.

The examples in this workshop will use the following tools:

Tool Path Description
csc <CORFolder>\csc.exe The C# compiler
fuslogvw <SDKFolder>\bin\fuslogvw.exe The Fusion log viewer
gacutil <SDKFolder>\bin\gacutil.exe The GAC utility
ildasm <SDKFolder>\bin\ildasm.exe The IL disassembly tool
nmake <SDKFolder>\bin\nmake.exe Program maintenance utility
sn <SDKFolder>\bin\sn.exe The strong name generator

Here, <CORFolder> is the location of the .NET framework assemblies (%systemroot%\Microsoft.NET\Framework\vx.x.xxx), <SDKFolder> is the location of the .NET SDK (usually it is in the Visual Studio folder). To do the examples in the workshop you should ensure that your command line path is set to give access to the folders in the table. The simplest way to do this is to run the vsvars32.bat file in the Common7\Tools folder in the Visual Studio .NET folder.

Cost

There is no charge for this tutorial, if this workshop was published as a book then you would pay $50 for it, if I were to give you this workshop as a training session then you would have to pay several thousand dollars, instead, you get it entirely for free. If you want to show your appreciation for the effort I have put into this workshop then please consider making a donation through Paypal. 

I give training courses and conference talks, and I write white papers and books on a variety of .NET topics; I also architect systems and perform code reviews. Please contact me if you want me to provide my services for you.

Contents

1. Loading Library Assemblies
1.1 Assembly Metadata
1.2 Loading Libraries and JIT Compilation
1.3 Fusion and PATH
1.4 Filenames
1.5 Subfolders
1.6 Versioning Without a Strong Name

2. Configuration File and Probing
2.1 Customizing the Private Path
2.2 Customizing Codebase

3. Strong Named Assemblies
3.1 Giving an Assembly a Strong Name
3.2 Using DEVPATH
3.3 Codebase with an Absolute Path
3.4 Loading an Assembly from the Internet
3.5 Versioning of Strong Name Assemblies
3.6 Versioning Rebinding
3.7 Versioning Redirection and Codebase
3.8 Delay Signing
3.9 Obfuscation of Strong Named Assemblies

4. Shared Assemblies
4.1 Shared Assemblies
4.2 Shared and Private Assemblies
4.3 GAC Folder Security

5. Utilities
5.1 Fuslogvw
5.2 Fixing Applications

6. Publisher Policy Files
6.1 Creating a Publisher Policy

7. GAC References
7.1 Adding a GAC Reference

8. Loading Assemblies Dynamically
8.1 Load and Invoke Through Reflection
8.2 Activating Objects
8.3 Local and GAC Assemblies
8.4 Partial Names
8.5 <qualifyAssembly>
8.6 AssemblyResolve Event

9. Resources and Satellite Assemblies
9.1 Embedded and Linked Resources
9.2 Compiled Resources
9.3 XML Compiled Resources
9.4 Culture Specific Resources
9.5 Strong Named Satellites
9.6 Satellite Versions
9.7 Delay Signing
9.8 Culture Specific Probing

10. Fusion API
10.1 Getting Access To The Fusion API
10.2 Listing The Managed Applications
10.3 Listing Files In The Assembly Cache
10.4 .NET Version 3.0/2.0

11. Fusion and the Compact Framework
11.1 CF Development
11.2 Private Assemblies
11.3 Locating Libraries
11.4 Versioning
11.5 The GAC
11.6 Programmatically Adding and Removing Assemblies From the GAC
11.7 Strong Name Verification
11.8 Concluding Remarks

12. Native Images
12.1 Loading an Assembly
12.2 Ngened Assemblies in .NET v1.1
12.3 Contents of Native Images in .NET 1.1
12.4 CLR Optimization Service in .NET 3.0/2.0
12.5 Logging Binding to Native Images
12.6 Automatic Redirect to Native Images
12.7 Deferred Updates
12.8 Hard Binding

13 Unmanaged Assemblies
13.1 Manifests and Side-by-Side Assemblies
13.2 Unmanaged Assembly Versioning
13.3 The Side-by-Side Cache
13.4 Side-by-Side Execution and Managed C++ Assemblies

14. Further Information
14.1 Books
14.2 Blogs

I hope that you enjoy this tutorial and value the knowledge that you will gain from it. This tutorial is free and will always remain free.

This page is (c) 2007 Richard Grimes, all rights reserved