There are three methods in the following classes:
LoadAssembly: Loading the assembly for the specified path
GetInstance: Dynamically getting instances from type, using generics to return types
Executemothod: Executing the specified method in the instance
/// <summary> ///inheriting from MarshalByRefObject means allowing cross-domain communication/// </summary> Public classRemoteloader:marshalbyrefobject {PrivateAssembly _assembly; Public voidLoadAssembly (stringassemblyfile) { Try{_assembly=Assembly.LoadFrom (assemblyfile); //return _assembly; } Catch(Exception ex) {Throwex; } } PublicT getinstance<t> (stringTypeName)whereT:class { if(_assembly = =NULL)return NULL; varType =_assembly. GetType (TypeName); if(Type = =NULL)return NULL; returnActivator.CreateInstance (Type) asT; } Public voidExecutemothod (stringTypeName,stringmethodName) { if(_assembly = =NULL)return; varType =_assembly. GetType (TypeName); varobj =activator.createinstance (type); Expression<Action> lambda = expression.lambda<action> (Expression.call (expression.constant (obj), type. GetMethod (MethodName)),NULL); Lambda.compile () (); } }
ASP. NET Dynamic loading assembly creates an instance of the specified class and invokes the specified method