24

Using reflection, I need to load 2 different versions of the same assembly. Can I load the 2 versions in 2 different AppDomains in the same process?

I need to do some data migration from the old version of the app to the new version. Please let me know if this is possible or should I use 2 separate processes.

starblue
  • 55,348
  • 14
  • 97
  • 151
Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170

2 Answers2

14

If you are doing it at design time (which you indicate you are not) this should help you:

http://blogs.msdn.com/abhinaba/archive/2005/11/30/498278.aspx

If you are doing it dynamically through reflection (looks like the case here) this might help you:

https://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
  • 1
    Yeah... The first one gives me, and a bunch of other guys, problems with "assembly already referenced". 7 year old post, and I still can't see any resolution or explanation in the comments field of that post. People of SO, help? – Nilzor Mar 07 '12 at 12:41
  • The InfoSysblog (second link) is a dead link now. Any suggestions? – Stealth Rabbi Jul 23 '13 at 15:47
5

UPDATE: I thought I will post my findings as an answer. Reflection proved too complex in terms of development effort, tracking run time errors etc. I remember doing a different approach using 2 different processes when faced with a similar situation long time back (Thank you Brandon).

This is the plan: Nothing elegant but easier in terms of development and troubleshooting. Since it is a one time job, we just have to make it work.

Host a remoting process (which i call the server) having the new version of the application. A remoting client has references for the older version.

Remoting client instantiates and loads the objects with data required for migration. Convert the old objects into common serializable objects and pass as parameters to the server.

Remoting Server uses the common data to instantiate and load the new objects. Invokes the functions on the new types to persist their data.

Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170