Reputation: 31
I'm getting the following error:
'MyNamespace.MyBaseClass' does not contain a definition for 'MyMethod' and no extension method 'MyMethod' accepting a first argument of type `MyMamespace.MyBaseClass' could be found (are you missing a using directive or an assembly reference?)
When I select the method in caller line and execute [Go to Definition], Visual Studio finds the method declaration at the expected place.
When method name is changed to MyMethod_ABC
and select [Generate method stub], the method MyMethod_ABC
is created next to MyMethod
with the same signature, only param names are different.
The project can't build. Someone can see something wrong ?
Upvotes: 3
Views: 18702
Reputation: 41
For anyone searching for a fix for this, as I was:
I just had this issue, but it turns out there was a small compilation error in the referenced Project containing the method I was trying to use and as that project hadn't ever compiled successfully with the new method in, the use of it in the other project was invalid. Fixed the bug and I no longer get this error.
Upvotes: 4
Reputation: 12574
I thought I had fixed this once over but then it came back. They way I fixed it permanently was this:
First I updated the version number for the assembly in AssemblyInfo.cs which can be found in the offending assemblies properties section in the solution explorer in Visual Studio.
I incremented it by 1. Next I removed the reference in my main project and re-added it. Finally I performed a clean and build of the offending project and looked for any errors. I could not see an error but there was a warning which related to an unused Exception variable. I removed this and did a complete rebuild of the whole solution and the problem was fixed.
Upvotes: 2
Reputation: 1
I just had this problem also. The method was there, and could be found with 'Go To Definition'. I changed the definition name (and the reference), and got the same error with the new name. I retyped the reference line, immediately above it, then deleted the old reference line, and voila-- it worked. No idea why, but rarely VS gets hung up on one line of code for some reason, with the only solution being to retype the line and delete the original. Odd. Well, this same problem came back. I noticed that the "missing" method would not show up in the list of methods matching what I start to type. Other methods from the same class would. This behavior would not change even if I renamed the method. So I figured the "blindspot" was correlated to the outward form of the particular method-- not just the name. So I copied another method from the same class that was "seen" by the IDE. I renamed it, deleted the internal code, then pasted in the in the internal code from the "unseen" method. Now it works consistently. A true "voila".
Upvotes: 0
Reputation: 998
I recently had the exact same problem. The solution was to delete the reference to the proyect in question, and add the same one again... Who knows, worked like a charm :)
Upvotes: 3
Reputation: 161
I got the same error after move class.cs from HtmlHelpers directory to Filters directory with VS interface after begin editing of code. Build, rebuild, clean not helps.
But how if you do not begin edit code? Drag class.cs from HtmlHelper directory and drop to Filters directory in my case. Then press F5 and no errors you will get. Then close VS, remove obj directory with dll, cache, tmp, DEBUG... in it. Run VS. Press F5 and no errors again.
Close VS, delete Obj directory and restart windows. Class.cs in the Filters directory, points to wrong HtmlHelpers directory in code. Press F5 and no errors again.
Upvotes: 0
Reputation: 1
Today, when turn on machine and open visual studio, the problem disapear, there was errors on other classes but on right code there is no red underline error indicator. Now the solution works fine. Thanks for everyone that look at it for me. Its a visual studio bug ? bye.
Upvotes: 0
Reputation: 754595
The ability to reference the method and "Go To Definition" succeeding are not 100% linked. While they use a lot of the same infrastructure they differ in a few key areas. Generally speaking "Go To Definition" will succeed in more cases than compilation will.
The most common causes of them not having the same result are
Given the particular error you are getting i would start with missing DLL / Project references
Upvotes: 2
Reputation: 243
If your code involves Cross projects references, verify if you included the project references, and verify the build order.
Upvotes: 0