In class Employee
I've got some methods, which work fine. Now I wanted to add new method, for example
public void ExampleMethod()
{
}
Then I call it
Employee employee = new Employee();
employee.ExampleMethod();
ExampleMethod is present in IntelliSense displayed after dot, when I hit F12 it also redirect me to that method, but while starting project I've got an error: 'Employee' does not contain a definition for 'ExampleMethod' and no extension method 'ExampleMethod' accepting a first argument of type 'Employee' could be found (are you missing a using directive or an assembly reference?)
I don't know why this error is caused, because all other earlier methods work fine. What's the problem?
I just ran into this problem; the issue seems different from the other answers posted here, so I'll mention it in case it helps someone.
In my case, I have an internal base class defined in one assembly ("A"), an internal derived class defined in a second assembly ("B"), and a test assembly ("TEST"). I exposed internals defined in assembly "B" to "TEST" using InternalsVisibleToAttribute
, but neglected to do so for assembly "A". This produced the error mentioned at top with no further indication of the problem; using InternalsVisibleToAttribute
to expose assembly "A" to "TEST" resolved the issue.
Create class with namespace name might resovle your issue
namespace.Employee employee = new namespace.Employee();
employee.ExampleMethod();
I had the same problem, "Rebuild Solution" and then "Clean Solution" didn't work.I solved that by checking my DLL references.
If you are using a class from another project, the project needs to re-build and create re-the dll. Make sure "Build" is checked for that project on Build -> Configuration Manager in Visual Studio. So the reference project will re-build and update the dll.
Today I encountered a problem with the exact same symptoms as you describe. I closed all files and restarted VS only to find out that some files disappeared from the Solution Explorer.
The following solved my problem: by selecting the current project in the Solution Explorer, a little icon Show all files
appears on the top bar. Right-clicking the file and selecting Include In Project
does the thing.
I had the same problem. I changed the Version of Assembly in AssemblyInfo.cs
in the Properties Folder. But, I don't have any idea why this problem happened. Maybe the compiler doesn't understand that this dll
is newer, just changing the version of Assembly.
I had the same problem. Turns out the project I was referencing did not get build. When I went to the build configuration manager in visual studio and enabled the reference project , the issue got resolved.
I had the same issue when working in a solution with multiple projects that share code. Turned out that I forgot to update the DLL in the folder of the 2nd project.
My suggestion is to take a good look at the 'project' column in the Error list window and make sure that project also uses the right DLL.
Source: Stackoverflow.com