Typeforwarding 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 whih contains 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 and end up with errors.
The Solution
Now, in order to run your applications without recompiling them, you can use the TypeForwarding 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.
Steps
Move the MyClass code from MyLibrary to MyAdvancedLibrary.
Put TypeForwardedToAtrribute in MyLibrary for the MyClasstype.
// C# Example
[assembly:TypeForwardedToAttribute(typeof(MyClass))]
Compile the newly created MyAdvancedLibrary.
Add a reference of MyAdvancedLibrary into MyLibrary.
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 typeforwarding 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++.
If you are quoting verbatim from an existing article (http://www.codeproject.com/Articles/27268/Type-Forwarding-in-NET), please give correct attribution.
Siva Shunmugam is a software Professional works for Effindi Technologies. He loves technology because it makes the life easy and likes socializing. By beeing a professional he comes to know about how the technology is beeing handled in the real time world. Among the many technological programes he uses and embraces SQL-SERVER, ASP.NET, JQUERY simply because he uses it in his profession.
DISCLAIMER
This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet/ BOL. My employer do not endorse any tools, applications, books, or concepts mentioned on the blog. I have documented my personal experience on this blog.
If you are quoting verbatim from an existing article (http://www.codeproject.com/Articles/27268/Type-Forwarding-in-NET), please give correct attribution.
ReplyDelete