简体   繁体   English

添加可选参数后System.MissingMethodException

[英]System.MissingMethodException after adding an optional parameter

I am getting error of System.MissingMethodException after I have an optional parameter in one component and the other component which call it was not build as it call it with old number of parameters. 我在一个组件中有一个可选参数之后得到System.MissingMethodException的错误,并且调用它的另一个组件没有构建,因为它使用旧的参数调用它。

Only component in which parameter is added was build an deployed as patch. 只有添加了参数的组件才会构建部署为补丁。 The calling component is old as there is no change in it. 调用组件是旧的,因为它没有变化。

When the calling component run it gives error : 当调用组件运行时,它会给出错误:

Exception Information 例外信息

Exception Type: System.MissingMethodException Message: Method not found: 'LabelURLs IPSD.BnB.Transaction.Postage.GetLabelURLs(System.String)'. 异常类型:System.MissingMethodException消息:找不到方法:'LabelURLs IPSD.BnB.Transaction.Postage.GetLabelURLs(System.String)'。 Data: System.Collections.ListDictionaryInternal TargetSite: Void GenerateScanForm(Int32, Int32) HelpLink: NULL Source: BnBDispenseQueueProcess 数据:System.Collections.ListDictionaryInternal TargetSite:Void GenerateScanForm(Int32,Int32)HelpLink:NULL源:BnBDispenseQueueProcess

As far as i know it should not raise an error as new parameter is optional. 据我所知,它不应该引发错误,因为新参数是可选的。 One more thing calling component(EXE) run as windows service. 还有一件事是调用组件(EXE)作为Windows服务运行。

we found an very wired workaround to make it run. 我们找到了一个非常有线的解决方法来让它运行。 By Removing the changed component once and run calling component which will say DLL not found. 通过删除更改的组件一次并运行调用组件,这将说明找不到DLL。 The place the same DLL again and calling component works fine:). 再次放置相同的DLL并调用组件工作正常:)。

I think i am missing some internals of .net. 我想我错过了.net的一些内部。

Let me know if more info needed. 如果需要更多信息,请告诉我。

Only component in which parameter is added was build an deployed as patch. 只有添加了参数的组件才会构建部署为补丁。 The calling component is old as there is no change in it. 调用组件是旧的,因为它没有变化。

There should be a change in it, because the old code calls a method which no longer exists! 应该有一个变化,因为旧代码调用一个不再存在的方法!

As far as i know it should not raise an error as new parameter is optional. 据我所知,它不应该引发错误,因为新参数是可选的。

That's not an execution-time decision - it's a compile-time decision. 这不是执行时决定 - 这是一个编译时决定。 If you have a method like this: 如果您有这样的方法:

void Foo(int x, int y = 5)

and you call it like this: 你这样称呼它:

Foo(10);

then the compiler effectively converts that into a call of: 然后编译器有效地将其转换为以下调用:

Foo(10, 5);

The call has the full argument list in the binary. 该调用在二进制文件中有完整的参数列表。 If you want to go from the single-parameter version to the multi-parameter version in a way which doesn't affect binary compatibility, you'd have to add an overload instead, eg 如果您想以不影响二进制兼容性的方式从单参数版本转到多参数版本,则必须添加重载,例如

void Foo(int x)
{
    Foo(x, 5);
}

void Foo(int x, int y)
{
    ...
}

Alternatively, you could rebuild the calling code and redeploy that as well. 或者,您可以重建调用代码并重新部署它。

I'm deeply suspicious of your workaround. 我对你的解决方法深感怀疑。 Are you sure you when you put the DLL back in place you replaced it with the new version (with the optional parameter) rather than the old version? 你确定当你把DLL放回原位时你用版本(带有可选参数)而不是旧版本替换它吗?

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

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