HCL
HCL

Reputation: 36775

Visual Studio c# compiler does not notice a changed method name

I have a really strange problem in a c# program:

I have an interface which declares a method and a class implementing this interface. When I change the methods name (in the interface and in the implementation), visual studio compiles the code, but if I run the code, I get a method not found exception. If I manually delete the target dll and recompile the project/solution, all works fine.

However, there are a lot of other methods and properties, also declared in the same interface and implemented in the very same class. If I change the name of one of them, all works fine!

Has anyone an idea, what this can be?

 public interface INode{
    //...
    IEnumerable<INode> Ancestors();
    //...
 }
 public abstract class NodeBase : INode{
    // ...
    public IEnumerable<INode> Ancestors(){

    }
    // ...
 }

Upvotes: 3

Views: 567

Answers (3)

HCL
HCL

Reputation: 36775

While trying to resolve the problem, I have removed the reference to the problem-assembly from the UI-project and then re-added. From this time on, the issue has been gone.

Sadly, I can not say what the reason for this really strange problem was, and now I have no more the opportunity to look at the issue. It must have been something corrupted within the project, however I can not imagine what this could have been, because really only one method signature was concerned (independent of the position in code and the name of the method).

Thanks to anybody who posted an answer so far (+1), leading me to a solution. I hope I will never see this weird behaviour again! For those having the same problem: try to recreate the references to the issuing project.

Upvotes: 2

David East
David East

Reputation: 32604

I get this problem all the time...

Usually I get save, close down VS, open the solution back up, and then build. This process keeps the issue at bay for a little while.

When you "Clean" a solution it deletes all the compiled and temporary files associated with a solution. It ensures that the next build will be from scratch.

I believe the problem lies with VS not properly building the solution and something gets "stuck". I also believe there are extensions for VS that help clear this problem.

This article maybe be a bit extreme for what you need, but you may find it useful: http://www.neovolve.com/post/2010/08/02/Cleaning-a-VS2010-solution-with-a-sledgehammer.aspx

Upvotes: 1

Whyrusleeping
Whyrusleeping

Reputation: 929

Have you tried doing a Build > Clean Solution/Project?

Upvotes: 1

Related Questions