在程序集中找不到入口点

发布于 2024-11-15 22:59:15 字数 950 浏览 5 评论 0原文

我有一个应用程序,我需要在其中创建 AppDomain 并将程序集加载到其中并执行程序集中的方法。

这是我的代码

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");
        }

}

我上面的代码写在一个名为 CreateAppDomain.cs 的类文件中

在我的 Default.aspx 页面中,我创建了上述类的实例并调用了 create 方法。这是

protected void Button1_Click(object sender, EventArgs e)
    {
        CreateAppDomain obj = new CreateAppDomain();
        obj.CreateAppDom();
        Response.Write("Application Domain Successfully created");
    }

我运行 default.aspx 页面时得到的 代码错误提示

在程序集“A1,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”中找不到入口点。

任何人都可以解释一下上述错误的含义及其解决方案。

谢谢,

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 code

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失去的东西太少 2024-11-22 22:59:15

AppDomain.ExecuteAssembly() 方法将程序集加载到指定的域中,然后执行它的标准入口点,即 static void Main(string[] args) 方法。

有关详细信息,请参阅此处

您想要的可能是 CreateInstanceAndUnwrap 的重载之一() 方法

编辑:

我创建了 ConsoleApplication9,除了 ClassLibrary1 之外还添加了。在 ClassLibrary1 中,我有 Class1

namespace ClassLibrary1
{
    public class Class1 : MarshalByRefObject
    {
        public void Go()
        {
            Console.WriteLine("My AppDomain's FriendlyName is: {0}", AppDomain.CurrentDomain.FriendlyName);
        }
    }
}

在 ConsoleApplication9 中,这些:

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();
}

运行时,我有:

尝试在当前域中运行方法...
我的 AppDomain 的友好名称是:ConsoleApplication9.exe

尝试在远程域中运行方法...
Class1 的程序集名称为:ClassLibrary1、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null
类型名称:ClassLibrary1.Class1

已创建远程实例。运行 Go() 方法:
我的 AppDomain 的友好名称是:我的远程域

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文