I have a .NET application that uses an assembly (.dll) that defines some method:
public void DoSomething()
{
// Do work
}
Suppose this method signature changes to include a string return type:
public string DoSomething()
{
// Do work
return "something";
}
Why does the code that uses this method fails on a System.MissingMethodException ?
It seems to me, that at all call sites to this method, no use was made of the return value (since it did not exist before).
Why does this change break the code then?
Because you did a breaking api change. You did either change the method signature in a base class or an interface.
The callers are linked against this method. In IL a method reference is not only a reference to a type and its method with some index to the method but the callers method references does include the complete method signature.
This change is therefore fixable by a recompile of all assemblies that call this method but you get run time exceptions when you only recompile the changed assembly and hope the the using assemblies will magically pick up the changed method signature. This is not the case because the method reference does contain the complete method signature and defining type.
It did happen to me also. You are right that nobody could use the return type so this change is safe but you need to recompile all affected targets.