views:

193

answers:

6

I have a simple interface:

public interface IVisitorsLogController  
{
    List<VisitorsLog> GetVisitorsLog();
    int GetUniqueSubscribersCount();
    int GetVisitorsCount();
    string GetVisitorsSummary();
}

the class VisitorsLogController implements this interface.

From a console application or a TestFixture - no problem - the console/test fixture compile perfectly.

However, from an Asp.Net web site (not application) in the same solution with this code in the code behind

private IVisitorsLogController ctl;

protected int GetUniqueMembersCount()
{
    ctl = new VisitorsLogController();
    return ctl.GetUniqueSubscribersCount();        
}

the compiler throws this exception:

Error 1 'WebSiteBusinessRules.Interfaces.IVisitorsLogController' does not contain a definition for 'GetUniqueSubscribersCount' and no extension method 'GetUniqueSubscribersCount' accepting a first argument of type 'WebSiteBusinessRules.Interfaces.IVisitorsLogController' could be found (are you missing a using directive or an assembly reference?)

yet for this code in the same file:

  protected static int GetVisitorsCount()
{
    return VisitorsLogController.Instance.GetVisitorsCount(DateTime.Today);
}

the compiler compiles these lines without complaining. In fact if I add anything new to the Interface the compiler now complains when trying to compile the asp.net page.

It can't be a missing using directive or assembly reference otherwise both methods would fail.

This is driving me nuts!

Any thoughts please?

Thanks,

Jeremy

A: 

I would start by checking the namespaces on each of the files involved and make sure that you don't have a conflict or a namespace that you are not expecting.

Mitchel Sellers
A: 

Out of interest, can you compile the following line:

ctl = VisitorsLogController.Instance;

? I'm just wondering if somehow you've got two interfaces named the same thing.

What does Intellisense prompt you with when you type ctl. and press Ctrl-Space?

Jon Skeet
John - yes that compiles fine. However as soon as I put in ctl.GetUniqueMembersCount() the compilation fails.Typing ctl.and Ctl+Space shows me GetUniqueMembersCount in the list. (I couldn't upload my screenshot).
Jeremy Holt
So if you accept Intellisense's own suggestion, it fails to build? Yikes. I suggest restarting Visual Studio and doing as clean a build as you can. It sounds like something's out of whack.
Jon Skeet
A: 

It would seem the other important bit of code would be VisitorsLogController, wouldn't it? It looks like VisitorsLogController is implementing a different IVistorsLogController interface.

Right clicking and GoTo Definition should clear things up, I think.

Mark Brackett
A: 

http://www.freeimagehosting.net/uploads/th.250a54cd57.gif" alt="alt text" />Wow - thanks for such a quick answer. I've just tried adding properties/methods to other interfaces in the web site - any additions to the existing interfaces cause the compilation to fail with the same error message as above. Lou - yes you're quite right. Intellisense picks up the methods as you can see in the attached screenshot. The first method - GetVisitorsCount() compiles fine. The next 4 methods fail. As you can see I'm accessing them both through the interface as well as through their implementations.

If I take the exact same code and paste it into a console app or a test fixture it compiles fine.

The only thing I can think of is that its something to do with web.config but I can't think where to start looking.

http://www.freeimagehosting.net/uploads/th.250a54cd57.gif" alt="alt text" />

[1]: http://www.freeimagehosting.net/>http://www.freeimagehosting.net/uploads/250a54cd57.gif border=0 alt="Free Image Hosting">

Jeremy Holt
A: 

There is only one IVisitorsLogController interface in the application. What really doesn't make any sense is that GetVisitorsCount() which is implemented in the same class from the same interface compiles fine. I went and added some new methods to other interfaces and had exactly the same problem - the new implementations fail to compile while the old one continue to compile fine. Note that this failure only occurs in the web site project in the solution. All the implementations of the interfaces in the other non website projects in the solution compile fine.

Jeremy Holt
A: 

I've just worked out what was happening - thanks Mark for the pointer.

In case this ever helps anyone else in the future ....

The solution contains the web site and three class projects (Data Layer, Service Layer and Core Services). They are added as references to the web site as Projects. I had compiled the solution at one point for Release - published the site, and then changed the config to Debug.

Evidently what had happened was that the Release dll's in the /bin file of the website were not being overwritten by the new Debug dll's. I manually deleted all the files in the /bin directory, and lo and behold - everything compiled perfectly.

So Mark and John - you were both spot on - I effectively did have two interfaces named the same thing.

Thanks very much for your help - if you hadn't given me these pointers I would never have finally worked it out.

Regards Jeremy

Jeremy Holt