Method not found on runtime

Solution 1:

"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.

Solution 2:

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)).

Solution 3:

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.