[c#] '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();
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?

This question is related to c# asp.net methods

The answer is


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.

Credit


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.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to methods

String method cannot be found in a main class method Calling another method java GUI ReactJS - Call One Component Method From Another Component multiple conditions for JavaScript .includes() method java, get set methods includes() not working in all browsers Python safe method to get value of nested dictionary Calling one method from another within same class in Python TypeError: method() takes 1 positional argument but 2 were given Android ListView with onClick items