I am trying to create and pass a Delegate from one AppDomain to another.
But it throws Error only when passing Delegates. If objects like String are passed, it works fine.
Also If the delegate is removed from setting through a constructor and set using a method, I am still unable to pass it to the object.
namespace TESTNS1 {
class Program {
static void Main(string[] args) {
try {
Program obj = new Program();
NS22.testappdom.MYDelT tt = new NS22.testappdom.MYDelT(obj.testingg);
NS22.testappdom obb = new NS22.testappdom(tt);
obb.invokeT();
AppDomain app1 = AppDomain.CreateDomain("newdom");
NS22.testappdom ob2 = (NS22.testappdom)app1.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(NS22.testappdom).FullName,
false, BindingFlags.Default, null, new object[] { tt }, null, null, null);
ob2.invokeT();
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
public bool testingg (Object obj) {
Console.WriteLine("testingg called..");
return false;
}
}
}
namespace NS22 {
class testappdom : MarshalByRefObject {
public delegate bool MYDelT(Object obj);
public MYDelT delee;
public testappdom() {
Console.WriteLine("Init.");
}
public testappdom(MYDelT dd) {
Console.WriteLine("Init1.");
this.delee = dd;
}
public void invokeT() {
this.delee(new Object());
}
}
}