简体   繁体   English

通过带有 DateTime 参数的 COM 调用方法导致找不到方法

[英]Invoking method via COM with a DateTime argument results in method not found

I'm trying to invoke a method from another DLL via a COM-server.我正在尝试通过 COM 服务器从另一个 DLL 调用一个方法。 When I pass an integer as argument (and change the method in the other dll to accept an integer) everything works fine.当我将 integer 作为参数传递(并更改另一个 dll 中的方法以接受整数)时,一切正常。 But when I try to pass a DateTime, it doesn't work and I get a method not found error.但是当我尝试传递 DateTime 时,它不起作用,并且我得到一个方法未找到错误。 I have no idea why.我不知道为什么。 Any ideas?有任何想法吗?

Note: the code calling the method is Visual Basic, the code on the 'receiving' end is C#.注意:调用该方法的代码是Visual Basic,“接收”端的代码是C#。

This works:这有效:

Caller:呼叫者:

Dim ComType As Type = Type.GetTypeFromProgID("Scheduling.ComServer")
Dim ComObject As Object = Activator.CreateInstance(ComType)

Dim methodArgs As Object() = New Object(0) {}
methodArgs(0) = 10
Dim result As String = CStr(ComType.InvokeMember("ScheduleItems", BindingFlags.InvokeMethod, Nothing, ComObject, methodArgs))

Method in other dll:其他 dll 中的方法:

public string ScheduleItems(int scheduleFrom)
{
    Scheduler scheduler = new Scheduler();
    return scheduler.ScheduleItems(new DateTime(2019, 11, 1));
}

This doesn't work:这不起作用:

Caller:呼叫者:

Dim ComType As Type = Type.GetTypeFromProgID("Scheduling.ComServer")
Dim ComObject As Object = Activator.CreateInstance(ComType)

Dim methodArgs As Object() = New Object(0) {}
methodArgs(0) = New DateTime(2019, 11, 1)
Dim result As String = CStr(ComType.InvokeMember("ScheduleItems", BindingFlags.InvokeMethod, Nothing, ComObject, methodArgs))

Method in other dll:其他 dll 中的方法:

public string ScheduleItems(DateTime scheduleFrom)
{
    Scheduler scheduler = new Scheduler();
    return scheduler.ScheduleItems(scheduleFrom);
}

So it turns out it was working just fine after all...所以事实证明它毕竟工作得很好......

Because the separate dll is... separate, I have to recompile it manually when I change it (it doesn't recompile when I run the calling application).因为单独的 dll 是......单独的,所以我必须在更改它时手动重新编译它(当我运行调用应用程序时它不会重新编译)。 And I forgot to do that when I changed the int to datetime.当我将 int 更改为 datetime 时,我忘记了这样做。 Goddamn it, now I lost 30 minutes and I feel stupid.该死的,现在我失去了 30 分钟,我觉得自己很愚蠢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM