System.MissingMethodException after adding an optional parameter

浪子不回头ぞ 提交于 2019-11-30 10:55:36

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, e.g.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!