I have a Application where I need to create AppDomain and Load Assembly into it and execute the methods in the Assembly.
Here is my Code
public class CreateAppDomain
{
public void CreateAppDom()
{
AppDomain domain = AppDomain.CreateDomain("myDomain");
domain.ExecuteAssembly(@"C:\Visual Studio 2005\Projects\A1\A1\bin\Debug\A1.dll");
domain.CreateInstanceFrom(@"C:\Visual Studio 2005\Projects\A1\A1\bin\Debug\A1.dll","A1.Navigate");
}
}
I above code is written in a classfile called CreateAppDomain.cs
In my Default.aspx page I created the instance of the above class and called the create method.Here is the cod开发者_StackOverflow中文版e
protected void Button1_Click(object sender, EventArgs e)
{
CreateAppDomain obj = new CreateAppDomain();
obj.CreateAppDom();
Response.Write("Application Domain Successfully created");
}
when I run the default.aspx page I get a error saying
Entry point not found in assembly 'A1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Can Anyone explain me the meaning of above error and solution to it.
Thanks,
AppDomain.ExecuteAssembly()
method loads an assembly into specified domain and then executes it's standard entry point i.e. static void Main(string[] args)
method.
Look here for details.
What do you want is probably one of the overloads of CreateInstanceAndUnwrap()
method
EDIT:
I created ConsoleApplication9, added besides ClassLibrary1. In the ClassLibrary1 I have Class1
:
namespace ClassLibrary1
{
public class Class1 : MarshalByRefObject
{
public void Go()
{
Console.WriteLine("My AppDomain's FriendlyName is: {0}", AppDomain.CurrentDomain.FriendlyName);
}
}
}
In the ConsoleApplication9 these's:
private static void Main(string[] args)
{
Console.WriteLine("Trying to run method in current domain...");
var inCurrentDomain = new Class1();
inCurrentDomain.Go();
Console.WriteLine("\nTrying to run method in remote domain...");
string asmName = typeof(Class1).Assembly.FullName;
string typeName = typeof (Class1).FullName;
Console.WriteLine("Class1's assembly name is: {0}\nType name: {1}", asmName, typeName);
var remoteDomain = AppDomain.CreateDomain("My remote domain");
var remoteObject = (Class1)remoteDomain.CreateInstanceAndUnwrap(asmName, typeName);
Console.WriteLine("\nRemote instance created. Running Go() method:");
remoteObject.Go();
}
When run, I have:
Trying to run method in current domain... My AppDomain's FriendlyName is: ConsoleApplication9.exe Trying to run method in remote domain... Class1's assembly name is: ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Type name: ClassLibrary1.Class1 Remote instance created. Running Go() method: My AppDomain's FriendlyName is: My remote domain
精彩评论