gromul
asked on
Load assembly from a file into app domain
How do I load assembly from a file into app domain? I need to load into a non-current app domain so I could unload the domain (and the loaded assembly in it) and then load another version of the assembly.
Here's what I have so far:
AppDomainSetup appDomainSetup = new AppDomainSetup( );
AppDomainSetup appDomainSetup.ShadowCopyF iles = "true";
AppDomainSetup appDomainSetup.Application Base = @"c:\Documents and Settings\user\Local Settings\Temp";
AppDomain appDomain = AppDomain.CreateDomain( "Test", null, appDomainSetup );
string filePath = @"C:\Documents and Settings\user\Local Settings\Temp\Test.dll";
string typeName = "Test.TestAssembly";
object o = appDomain.CreateInstanceFr omAndUnwra p( filePath, typeName );
The latest error I'm getting is "Type is not resolved for member 'Test.TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'".
Thanks
Here's what I have so far:
AppDomainSetup appDomainSetup = new AppDomainSetup( );
AppDomainSetup appDomainSetup.ShadowCopyF
AppDomainSetup appDomainSetup.Application
AppDomain appDomain = AppDomain.CreateDomain( "Test", null, appDomainSetup );
string filePath = @"C:\Documents and Settings\user\Local Settings\Temp\Test.dll";
string typeName = "Test.TestAssembly";
object o = appDomain.CreateInstanceFr
The latest error I'm getting is "Type is not resolved for member 'Test.TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'".
Thanks
Your classs TestAssembly needs to inherit from MarshalByRefObject for this to work. Cross appdomain calls are marshalled by the .NET Remoting
ASKER
What if the TestAssembly class already inherits from another class over which I don't have control? Can interfaces be used as an alternative? I tried implementing ISerializable but that didn't work.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.