Clicky Web Analytics Moving a Type from one assembly to another (TypeForwardTo Attribute) - Brenton House

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://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.typeforwardedtoattribute.aspx

 

</snip>

 

Published Friday, April 28, 2006 8:47 AM by dotnetboy2003

Comments

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

One problem is that you have to "Recompile and redeploy both assemblies". It will be much better if I don't need to touch the old assembly, :-).

Friday, April 28, 2006 9:14 AM by anonymous coward

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

True. I wouldn't recommend it unless you couldn't recompile the assembly that had the dependencies and you HAD to move the type.

Friday, April 28, 2006 9:45 AM by Brenton House

Leave a Comment

(required) 
(required) 
(optional)
(required)