Moving a Type from one assembly to another (TypeForwardTo Attribute)

[via Irena Kennedy’s Blog]

<snip>

Do you remember the old TreatAs registry setting for COM classes?  If you want a quick refresher, check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/1d7a1677-738a-4258-9afc-e77bd0dcf40f.asp.

 

Well, TypeForwardedTo attribute is kind of like that… You use the TypeForwardedToAttribute attribute to move a type from one assembly to another without disrupting callers that compiled against the old assembly.  This allows you to reorganize your libraries without breaking compatibility with applications using them.

 

Bill Bozeman has a good explanation of it with a code sample at http://www.bozemanblog.com/PermaLink,guid,2e6d7675-eb43-438f-8b93-9155ca1712fa.aspx.

 

To summarize the steps, here is what you need to do:

  1. Create a new assembly
  2. Move the class from the old assembly to the new.  Make sure to keep same namespace.
  3. Remove the class from the old assembly.
  4. In the old assembly, add a reference to the new assembly.
  5. Add [assembly: TypeForwardedTo(typeof(YourClassName))] to the old assembly
  6. Recompile and redeploy both assemblies

 

References: 

http://notgartner.com/posts/2955.aspx

http://www.bozemanblog.com/PermaLink,guid,2e6d7675-eb43-438f-8b93-9155ca1712fa.aspx

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.typeforwardedtoattribute.aspx

 

</snip>

 

Recent Posts

Tag Cloud

2 Comments

Comments have been disabled for this content.