‘Class’ does not contain a definition for ‘Method’

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();

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?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There are three possibilities:

1) If you are referring old DLL then it cant be used. So you have refer new DLL

2) If you are using it in different namespace and trying to use the other namespace’s dll then it wont refer this method.

3) You may need to rebuild the project

I think third option might be the cause for you. Please post more information in order to understand exact problem of yours.

Method 2

Create class with namespace name might resovle your issue

namespace.Employee employee = new namespace.Employee(); 

Method 3

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.

Method 4

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.

Method 5

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.

Method 6

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.

Method 7

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.


Method 8

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.

Method 9

I had the same problem, “Rebuild Solution” and then “Clean Solution” didn’t work.I solved that by checking my DLL references.

Method 10

When I had the same error,

dotnet restore

Resolved it. From the docs:

dotnet restore – Restores the dependencies and tools of a project.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x