Inline...
> Nicole,
>
[quoted text clipped - 5 lines]
> myNewEvidence.AddHost(new Url(@"file://c:/temp"));
> myNewEvidence.AddHost(new Zone(SecurityZone.Trusted));
Unless you have elevated the CAS permissions grant for the trusted zone,
your evidence-reading code won't work in that zone. You'll need to use the
MyComputer zone or add some other evidence that would allow the necessary
permissions to be granted.
> AppDomain myNewAppDomain = AppDomain.CreateDomain("new
> domain",myNewEvidence);
[quoted text clipped - 9 lines]
> MethodInfo [] miMethods = typeHelloWorld.GetMethods();
> Object objHelloWorld = Activator.CreateInstance(typeHelloWorld);
First big problem is right here. The instance is getting created in the
original appdomain because that's where the type is defined.
> for (int i =0 ; i < miMethods.Length ; i++)
> {
> if(miMethods[i].Name == "DisplayEvidence2")
> {
> miMethods[i].Invoke(objHelloWorld, new Object[0] );
Second big problem is here. The method is being invoked in the original
appdomain because that's where the methodinfo is defined.
> }
>
> }
>
> Is the DisplayEvidence2 method in the original application domain?
Yup.
> I mean
> for it to get called in the new application domain.
You'll need to do two big things differently to get this to work. First,
you'll need to ensure that the HelloWorld object gets created in the new
appdomain. You'll then need to call the method against that remote
instance of the object, not against a local wrapper instance in the original
appdomain. Here's a version that should work:
Evidence myNewEvidence = new Evidence();
myNewEvidence.AddHost(new Url(@"file://c:/temp"));
myNewEvidence.AddHost(new Zone(SecurityZone.MyComputer));
AppDomain myNewAppDomain = AppDomain.CreateDomain("new domain",
myNewEvidence);
try
{
// The HelloWorld instance will be created in the new appdomain even
though the reference is
// held in the original appdomain:
Hello.HelloWorld helloWorldInstance =
(Hello.HelloWorld)myNewAppDomain.CreateInstanceFromAndUnwrap(@"C:\temp2\HelloWorld.dll",
"Hello.HelloWorld");
// This will execute in the original appdomain:
helloWorldInstance.DisplayEvidence2();
// This will execute in the new appdomain:
myNewAppDomain.DoCallBack(new
CrossAppDomainDelegate(helloWorldInstance.DisplayEvidence2));
}
finally
{
AppDomain.Unload(myNewAppDomain);
}
> -jas
>
[quoted text clipped - 48 lines]
>> >
>> > -jas