Click here to Skip to main content
13,599,044 members
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 25 Jun 2008
Licenced CPOL

Type Forwarding in .NET

, 24 Aug 2008
Rate this:
Please Sign up or sign in to vote.
Type forwarding is a CLR feature that allows us to move a type from its original assembly to another assembly.


Type forwarding is a CLR feature that allows us to move a type from its original assembly to another assembly in such a way that there is no need to recompile the applications referring to the original assembly.

The Requirement

Suppose you have created an assembly named MyLibrary which contains a class named MyClass. Let's say, some of your applications refer to the MyLibrary assembly and utilizes MyClass. In a later phase, you decide to move MyClass from MyLibrary to a newly created assembly called MyAdvancedLibrary. If you ship a new version of MyLibrary (which now doesn't have MyClass), along with MyAdvancedLibrary, then your existing applications looking for MyClass in MyLibrary will not find the MyClass and end up with errors.

The Solution

Now, in order to run your applications without recompiling them, you can use the Type Forwarding feature of the Common Language Runtime.

In the above scenario, you need to apply TypeForwardedToAttribute to the new version of your MyLibrary, so that requests for MyClass are now forwarded to the newly created library MyAdvancedLibrary that now contains MyClass.


  1. Move the MyClass code from MyLibrary to MyAdvancedLibrary.
  2. Put TypeForwardedToAtrribute in MyLibrary for the MyClass type.
  3. // C# Example
  4. Compile the newly created MyAdvancedLibrary.
  5. Add a reference of MyAdvancedLibrary into MyLibrary.
  6. Recompile MyLibrary (because MyClass used to be located in that).

Now, you can ship the new version of MyLibrary along with MyAdvancedLibrary and run your applications without a recompile!

The Limitation

The .NET Framework version 2.0 does not allow type forwarding from assemblies written in Visual Basic. However, a Visual Basic application can consume forwarded types if it uses the assemblies coded in C# or C++.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

I started programming for fun when I was in Higher Secondary (1995). It was a table writing program in C..haah!! those were the best days of my life Smile | :)

But now it has brought me to no. of jobs in roles of developer, Lead, Architect, Coach and Consultant....

.Net c# is my passion specially when it comes to build api and frameworks to facilitates development teams....

I always learned things by example, now its a pleasure and responsiblity to give learnings back to next generation of coders.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey26-Feb-12 21:10
membermanoj kumar choubey26-Feb-12 21:10 
Generalasked about the library! Pin
thangnx25-Apr-11 22:53
memberthangnx25-Apr-11 22:53 
GeneralMy vote of 5 Pin
bara-brg20084-Aug-10 16:40
memberbara-brg20084-Aug-10 16:40 
GeneralType Forwarding in .NET Pin
Aslam Parvez Memon25-Dec-09 9:54
memberAslam Parvez Memon25-Dec-09 9:54 
GeneralThank you Pin
Ted James19-Nov-09 23:42
memberTed James19-Nov-09 23:42 
GeneralGreat Info Pin
merlin9814-Sep-08 11:06
membermerlin9814-Sep-08 11:06 
GeneralNice 1 Pin
ashu fouzdar4-Sep-08 0:45
memberashu fouzdar4-Sep-08 0:45 
GeneralRe: Nice 1 Pin
Qwertie9-Sep-08 14:42
memberQwertie9-Sep-08 14:42 
GeneralRe: Nice 1 Pin
Bhupindra Singh9-Sep-08 20:24
memberBhupindra Singh9-Sep-08 20:24 
GeneralNice info Pin
Dinesh Mani25-Aug-08 17:40
memberDinesh Mani25-Aug-08 17:40 

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 | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180621.3 | Last Updated 25 Aug 2008
Article Copyright 2008 by Bhupindra Singh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid