Sunday, August 11, 2013

Working with multiple AppDomain

AppDomain is a very use-full, when we are working with same assembly of multiple version. here is a sample code which will execute different assembly (but with same name and same method). what you need to do before? Assuming you have below folder structure to compile project

1. Create an interface (not important, but it is good to have)


build this project to "Binaries" folder
2. Create another project, which is we are going to execute (say V1)

 

 build this project to "V1" folder

3. Create another project, which should be same as above "V1" project.( do not change namespace name, class name and method name)
just change the return string as "This is calling from "V2" (ie string msg = "This is calling from V2";)

build this project to "V2" folder

4. Now we need to create Main project to run this all. Create a console application.

a. add a method, which shuld create new appDomain.


(Click on the above image to view in actual size)

now we are going to run this all.

Here we are not refer any of those 2 assemblies, but we will load assembly by using "reflection".


(Click on the above image to view in actual size)

No comments: