I have an ASP.Net c# project trying to access methods in a class in another project. It's working for first half of methods in the class but not for the other half of the methods in the class which I recently added. They compile, but they throw a method not found exception at run-time.
Does anyone have any ideas I could try? I've tried:
.sln
file"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 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)).
Two projects in your solution : project A and project B. Both projects use the nuget package "DoStuff", but different versions of the DoStuff package:
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 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.
had the same problem, in my case setting the optimizeCompilations to false in the webconfig solved the problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With