19

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?

3
  • 2
    can you post your full employee class? Clean + rebuild all might help
    – KyorCode
    Sep 18, 2012 at 10:30
  • Try manually update your assembly in GAC Sep 18, 2012 at 10:32
  • Clean and Rebuild worked! Thank you very much :D
    – vanilla161
    Sep 18, 2012 at 10:36

10 Answers 10

26

There are three possibilities:

  1. If you are referring an old DLL then it can't be used. So you have to refer to a new DLL.

  2. If you are using it in a different namespace and trying to use the other namespace's dll then it won't refer to 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.

4
  • 2
    4) The OP may have got confused with some sort of class ambiguity and referenced an incorrect Employee class from a different assemply/project? +1.
    – user1017882
    Sep 18, 2012 at 10:42
  • +1 -> Don't name your Entity Framework Database tables the same as classes... Doh.
    – teynon
    Jul 23, 2013 at 13:38
  • 1
    I just had to clean and rebuild
    – KthProg
    Dec 29, 2016 at 17:23
  • I had to clean and rebuild the solution, not only the project. Feb 17, 2021 at 13:25
6

Create class with namespace name might resovle your issue

namespace.Employee employee = new namespace.Employee(); 
employee.ExampleMethod();
1
  • I manually added the namespace before every class call. This worked for me.
    – Atanu Roy
    Apr 7, 2014 at 12:24
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.

2

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.

1

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.

0
1

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.

0

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.

Credit

0

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.

1
  • Thanks for the suggestion about the project column. In ASP.NET, Global.asax is considered in a different project than the rest of your code, it seems? So you cannot call internal/friend methods from Global.asax. Very annoying.
    – user169771
    May 6, 2015 at 21:07
0

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

0

When I had the same error,

dotnet restore

Resolved it. From the docs:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.