English 中文(简体)
Activator.CreateInstance (string, string)hanging FormatLoadException
原标题:Activator.CreateInstance(string, string) throwing TypeLoadException

我有以下法典:

public static void Invoke(string assemblyName, string scheduledTaskExecutorName)
{
    ObjectHandle objectHandle = Activator.CreateInstance(assemblyName, scheduledTaskExecutorName);
    IScheduledTaskExecutor scheduledTaskExecutor = (IScheduledTaskExecutor)objectHandle.Unwrap();
    scheduledTaskExecutor.ExecuteScheduledTask();
}

页: 1 DummyS subuledTaskExecutor 参看:

public class DummyScheduledTaskExecutor : IScheduledTaskExecutor
{
    public void ExecuteScheduledTask()
    {
        DummyTextFile.Text = "Success!";
    }
}

它居住在一个大会,其组织名称(按组别的界定)为<代码>。 申请。 Unit 。

我请<条码>Invoke(指示、指示)。

ScheduledTaskInvoker.Invoke("Tests.WebApplication.Application.Unit", "DummyScheduledTaskExecutor");

试图实施这一法典只是扔下了一种LoadException型号。 我是否表示集会或名称不正确,或者说还有什么?

最佳回答

计划设立的TaskExecutorName需要包括名称空间。

请将全名空间列入你的第二个参数。

我的例子:

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            object obj = Activator.CreateInstance(null, "WindowsFormsApplication6.TestClass");
        }
    }
}

namespace WindowsFormsApplication6
{
    public class TestClass
    {

    }
}
问题回答

你是否尝试了大会具有约束力的记录?

<>CreateInstance将假定大会已经装满。 我的猜测实际上是 t。 你们需要使用<>CreateInstanceFrom。

EDIT:如果你知道会装满,则最有可能出现与你创建娱乐的参数有关的问题。 现在使用完全合格的类别名称,而不是像你这样简单的类别名称。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签