Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

my application want to call a method of a class that is from another AppDomain.

       AppDomain env = AppDomain.CreateDomain(
            "test",
            null,
            new AppDomainSetup() { ApplicationName = "test" }
            );

        Assembly a = Assembly.LoadFrom("d:\testenv1\test2.dll");
        //env.AssemblyResolve += new ResolveEventHandler(env_AssemblyResolve);
        env.Load(a.FullName);

        ObjectHandle o = env.CreateInstance(a.FullName, "Test2.Class1");

now i have the object handle of the Test2.Class1, but i have no idea how to invode the "action" method of the Class1 class.

the "action" method likes this:

    public void action()
    {
        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName + " ok");
    }

i tried to use o.unwrap() method to get the reference of the object, but it seems the object has been transferred into the current domain, so the output of the "action" method prints the current domain name.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

Mark the object that you want to use for cross appdomain communication as MarshalByRefObject.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...