装配中找不到入口点 [英] Entry point not found in assembly

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

问题描述

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

I have a Application where I need to create AppDomain and Load Assembly into it and execute the methods in the Assembly.

这是我的代码

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的类文件

I above code is written in a classfile called CreateAppDomain.cs

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

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

当我运行default.aspx页面时,出现错误提示

when I run the default.aspx page I get a error saying

在程序集'A1中找不到入口点,版本= 1.0.0.0,文化=中性,PublicKeyToken =空'。

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.

谢谢,

推荐答案

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

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.

查找此处了解详情。

您想要的可能是 CreateInstanceAndUnwrap()方法

What do you want is probably one of the overloads of CreateInstanceAndUnwrap() method

编辑:

我创建了ConsoleApplication9,除了ClassLibrary1。在ClassLibrary1中,我有 Class1

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

在ConsoleApplication9中,这些是:

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

运行时,我有:


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天全站免登陆