Method not found on runtime
Two projects in your solution : project A and project B. Both projects use the nuget package "DoStuff", but different versions of the DoStuff package:
- project A references version 1.1 of DoStuff.
- project B references version 1.0 of DoStuff.
- project B references project A.
version 1.1 has a new method, that is used in project A. when project B uses project A, you'll get this MethodNotFoundException, because project B's version of DoStuff doesn't know what project A is talking about.
To prevent this, we have a unit test in place that fails if projects are using different versions of the same nuget package. A relatively simple doorstop that has saved us a couple of headaches in the past years.
I had the same issue. In my case, it was caused by the addition of an optional argument. So first you would have:
referencingAssembly:
referencedAssembly.DoStuff(firstArgument, secondArgument)
referencedAssembly:
public void DoStuff(string firstArgument, string secondArgument)
{
//stuff to do
}
Then you add an optional parameter to the method, but you don't provide that argument while calling it.
referencingAssembly:
referencedAssembly.DoStuff(firstArgument, secondArgument)//unchanged
referencedAssembly:
public void DoStuff(string firstArgument, string secondArgument, string thirdArgument = "default value")
{
//stuff to do
}
Locally, this will build and run fine since the newly build referencingAssembly.dll will have a reference to the DoStuff(string, string, string) method. But when you only deploy the changed referencedAssembly (thinking: the added argument was optional, and the referncingAssembly still works), the old version of referencingAssembly will throw a MethodNotFound since it seeks a method with the signature DoStuff(string, string), which is no longer present in the referencedAssembly since we added the extra (optional) argument.
A possible solution could be an overload:
referencedAssembly:
public void DoStuff(string firstArgument, string secondArgument)//original method
{
DoStuff(firstArgument, secondArgument, "default value")
}
public void DoStuff(string firstArgument, string secondArgument, string thirdArgument)//new overload of the method
{
//stuff to do
}
Or deploying the newly build referencingAssembly (which will refer to the method with signature DoStuff(string, string, string)).
"Method not found" is a very specific error, which means a method it expected (i.e. was there at compile time) simply is not present. This usually means that the files you are deploying are different to what you think they are - specifically, I would wager that you are deploying the old version of the library (which lacks your additions).
Check the dlls deployed to the web-server against what you think they should be.
I have faced this kind of problem but was able to solve it. I emptied my bin and debug folder and tried building the project again. it worked, at least for me. Or try to clean the solution and try rebuilding it. But of course, posting a part of your code could be more helpful.