Type Forwarding

This article covers a .NET 2.0 concept that helps developers overcome DLL hell. For those of you who have never experienced DLL hell this article might be a little confusing.

Type forwarding is an ‘attribute’ in the .NET framework that allows you to move members from assembly X to assembly Y without recompiling clients that use Assembly X.

Lets say you have shipped an application called HackRz that utilizes an assembly called utilities.dll.
Suppose you now have now created another ‘new’ application called CrackRz. The new CrackRz also utilises utilities.dll (shared dll). The problem is that you might have refactored and improved utilities.dll by moving a member called FBIBreaker from utilities.dll to illlegalUtilities.dll.

Now you ship CrackRz together with the two new assemblies. Installing the new Crackaz application and replacing the ‘old’ utilities.dll with the new ‘utilities.dll’ would break down the HackRz application because HackRz expects there to be a type called FBIBreaker in utilities.dll. (remember FBIBreaker was moved to IllegalUtilities.dll !!)
This is where type forwarding comes to the rescue.

What you are supposed to do is:

1. Cut the definition of hackFBI from Utilities. In its place put the TypeForwardedTo attribute

[assembly: TypeForwardedTo(typeOF(IllegalUtilities.FBIBreaker)))]

2. Paste the definition of FBIBreaker into DangerousUtilities.

3. Rebuild both Assemblies and ship.

What now happens is… all requests made by HackRz for type FBIBreaker are forwarded to the assembly IllegalUtilities. Also CrackRZ can continue to use the new improved utilities.dll.

CrackRz and HackRz can run happily side by side and we can continue to hack and crack !!!

If you don’t understand this confusing concept then move along then coz I have done my best to explain it. Its been a while since i have written and posted anything serious

3 Responses to “Type Forwarding”

  1. Nataliya Says:

    Hi,

    Thanks so much for such excellent explanation!!!

  2. mm Says:

    http://msdn.microsoft.com/en-us/library/ms404275.aspx

  3. Yogesh Says:

    Thank
    this is nice article
    it greate ! if an example also given.

Leave a Reply