Monday, April 11, 2011

How to resolve incorrect "Ambiguous reference" from Resharper on class inheritance?

In my project I have a class that is inherited by many other classes. We'll call it ClassBase.

public class ClassInheritFromBase : ClassBase

When ClassBase is being inherited, Resharper throws an "Ambiguous reference" warning on the ClassBase, and anything inside the new class that inherited from ClassBase does not have Intellisense and gets warnings that it cannot find it.

The project compiles and run fine.

If I change the namespace ClassBase is in and then change the inheriting classes, they find it fine and Resharper has no problem, Intellisense works ... until it is compiled. After the compile it goes back to having the ambiguous reference warnings and everything else.

Anybody seen this before and know how to fix? I saw an entry in JetBrains bug tracking for an issue just like this, but they closed it as unable to reproduce.

From stackoverflow
  • Haven't run into this problem myself. Have you tried to reopen the bug with these new steps to recreate ?

    Carlton Jenke : not yet. I was hoping SO could have an answer faster than JetBrains. That would be the next step if no one here knows.
  • same problem here:

    public partial class WebPage1 : MyNamespace.BaseWebForm  << [ambiguous reference]
    {
        if ( !Page.IsPostBack )  << [inherited Page is not recognized by ReSharper]
        {
        }
    }
    
  • I am having a similar problem even without inheritance. I have a class in my project called ShipmentInfo and I am creating an instance in my code called shipmentInfo. This worked fine in Visual Studio 2008 on a box with Windows Server 2003 and SQL Server 2005 but not when I moved it over to a Windows Server 2008 box with SQL Server 2008, or maybe I never noticed it.

    Anyway, it builds fine, but shows tons of "ambiguous reference" errors in ReSharper. I refactored the name to currentShipmentInfo just in case ReSharper didn't like the name being the same except for case, but had the same problem.

    I also tried renaming my class to ShipmentInfoX and then referencing that new class and it worked fine for one build, but then the "ambiguous reference showed up again. It seems like ReSharper is caching the class somewhere and that cached class is somehow visible to the code as a separate class. Weird.

    Any ideas?

  • I've seen this bug in resharper 4.1. It happens when the base class is in the App_Code directory. Don't know how to fix it, very annoying, code still compiles though.

  • I have this same problem. Any ideas on how to fix it?

  • This is a bug in resharper 4.1 and is fixed in one of the later nightly builds

    Download the last nightly build here http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds

  • I encountered the same problem. The issue I had was caused by a custom build provider (from an open source library I'm using called PageMethods) and the fact that all my .aspx pages inherit from a BasePage class which lives in the App_Code folder.

    I couldn't get any build of Resharper to work with my project (4.1.933, 4.1.943 (latest) or 4.5). The fix in the latest Resharper build fixes the "Ambiguous Reference" problem but breaks the custom build provider.

    The only way I could get both the build provider and base classes to work with Resharper was to put the Base Classes into a separate class library.

    The following are the logged Jira bugs that seem to relate to this issue:

  • I was experiencing the same problem with references to C# classes in the AppCode folder.

    I resolved this by upgrading my ReSharper to version 4.5 (from version 4.1).

    It was a very simple upgrade, I just had to get the latest version from the JetBrains website (http://www.jetbrains.com/resharper/download/) and run it.

    I did not have to uninstall the previous version (v4.1). I did not have to re-enter my existing licence key.

    All references are now recognised correctly and I can naviage to the classes as expected.

  • Still same problem exists in version 4.5. I disabled resharper and native VS2008 intellisense works with no warnings for ambiguous references.

  • ReSharper -> Options -> General: Click # Clear Caches # button.

0 comments:

Post a Comment