在程序集中找不到入口点 [英] Entry point not found in assembly

查看:23
本文介绍了在程序集中找不到入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我的代码

公共类 CreateAppDomain{公共无效 CreateAppDom(){AppDomain 域 = AppDomain.CreateDomain("myDomain");domain.ExecuteAssembly(@"C:Visual Studio 2005ProjectsA1A1inDebugA1.dll");domain.CreateInstanceFrom(@"C:Visual Studio 2005ProjectsA1A1inDebugA1.dll","A1.Navigate");}}

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

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

protected void Button1_Click(object sender, EventArgs e){CreateAppDomain obj = new CreateAppDomain();obj.CreateAppDom();Response.Write("应用域创建成功");}

当我运行 default.aspx 页面时,我收到一条错误消息

在程序集A1,版本=1.0.0.0,文化=中性,PublicKeyToken=null"中找不到入口点.

谁能解释一下上述错误的含义和解决方法.

谢谢,

解决方案

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

查看此处了解详情.

你想要的可能是<的重载之一代码>CreateInstanceAndUnwrap() 方法

我创建了 ConsoleApplication9,添加到 ClassLibrary1 之外.在 ClassLibrary1 我有 Class1:

命名空间 ClassLibrary1{公共类 Class1 : MarshalByRefObject{公共无效去(){Console.WriteLine("我的 AppDomain 的友好名称是:{0}", AppDomain.CurrentDomain.FriendlyName);}}}

在 ConsoleApplication9 中,这些是:

private static void Main(string[] args){Console.WriteLine("试图在当前域中运行方法...");var inCurrentDomain = new Class1();inCurrentDomain.Go();Console.WriteLine("
试图在远程域中运行方法...");string asmName = typeof(Class1).Assembly.FullName;string typeName = typeof (Class1).FullName;Console.WriteLine("Class1 的程序集名称为:{0}
类型名称:{1}", asmName, typeName);var remoteDomain = AppDomain.CreateDomain("我的远程域");var remoteObject = (Class1)remoteDomain.CreateInstanceAndUnwrap(asmName, typeName);Console.WriteLine("
远程实例已创建.运行 Go() 方法:");remoteObject.Go();}

运行时,我有:

<块引用>

试图在当前域中运行方法...我的 AppDomain 的 FriendlyName 是:ConsoleApplication9.exe试图在远程域中运行方法...Class1 的程序集名称为:ClassLibrary1,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null类型名称:ClassLibrary1.Class1远程实例已创建.运行 Go() 方法:我的 AppDomain 的 FriendlyName 是:我的远程域

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 2005ProjectsA1A1inDebugA1.dll");
        domain.CreateInstanceFrom(@"C:Visual Studio 2005ProjectsA1A1inDebugA1.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,

解决方案

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("
Trying 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}
Type name: {1}", asmName, typeName);

    var remoteDomain = AppDomain.CreateDomain("My remote domain");
    var remoteObject = (Class1)remoteDomain.CreateInstanceAndUnwrap(asmName, typeName);
    Console.WriteLine("
Remote 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

这篇关于在程序集中找不到入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆