13

In one of my solutions, when I right click a symbol and choose "Go To Implementation" for an object defined in one of the other solution projects, it lists the reference twice and forces me to choose one.

Based on the icons, it appears that one of the items in the list represents the project, and the other represents a dll. It doesn't matter which one I click - it goes to the same source file.

I only have the library reference once in this particular project - it is referencing the project.

What would cause this to happen? Some sort of circular reference issue perhaps?

Shaun Rowan
  • 9,269
  • 4
  • 28
  • 52
  • This is difficult to diagnose from the description you give. Could you please describe your case in detail at http://youtrack.jetbrains.net - thanks! – Dmitri Nesteruk Jun 18 '13 at 15:16
  • I have the same issue. Are you using EntityFramework or any technology that might cause the DLL to be loaded by some Visual Studio tooling? – Josh Gallagher Aug 22 '13 at 11:22
  • Yep, using EF code first. – Shaun Rowan Aug 23 '13 at 21:05
  • I'm having the same issue spasmodically and I'm using EF Code First as well... I haven't seen this issue before on previous projects that don't use EF... – Tod Thomson Oct 21 '13 at 07:22
  • It the file linked (i.e Add as link) between projects? – atomaras Nov 08 '13 at 20:36
  • These answers all help in various ways but the underlying problem will crop up again in the future as Resharper once again caches the assembly after a build. Speaking from experience. Happens to me pretty much daily. I have created an "issue" on the [JetBrains](http://youtrack.jetbrains.com/issue/RSRP-417292) site. It would help them give it a higher priority if people would go to there and up vote it. This caching is also the cause of [a different problem](http://youtrack.jetbrains.com/issue/RSRP-417293) related to the Rename functionality. – Andrew Steitz Jul 02 '14 at 17:58

3 Answers3

2

As far as I can tell, this can also happen if you have a solution with several projects, where a certain project is referenced as project and also as pure file by two other projects in the solution.

Another advice that I can give if something is broken with ReSharper, is to clear the cache.

Community
  • 1
  • 1
Matthias
  • 15,919
  • 5
  • 39
  • 84
  • How can I tell by looking at an existing reference whether it is referenced as a project or referenced as a file? Resharper can add a reference for me so maybe it has done it the wrong way. – Matt Frear Jan 30 '14 at 21:12
  • @MattFrear: you need to have a look at the csproj file. – Matthias Mar 06 '14 at 11:08
  • I cleared the old R# versions in %LOCALAPPDATA%\JetBrains\ReSharper and then the specific solution cache in my current 8.2 version and the problem went away after restarting VS. – SilverSideDown Apr 03 '14 at 13:29
2

I had this problem and I just fixed it.

First, try do a Clean Solution and then a Build.

In my case, one rogue Project in my solution was compiled using an older version of the .NET framework than the other Projects, so when Resharper added a reference to my other Projects for me, it must have added it as a dll reference instead of as a Project reference.

My fix was

  1. Upgrade old Project to the same version of .NET framework as the other Projects
  2. Remove references to other Projects from that old Project
  3. Add references to the other Projects again (as Project references this time)
  4. Clean solution
  5. Build solution

Done.

Matt Frear
  • 52,283
  • 12
  • 78
  • 86
1

I've found a couple different cases that cause this problem, and got so annoyed that I wrote a little console app to scan my solution and find the problems for me. Here it is for anyone who might find this useful. To run it pass it the path to your solution folder and it will print out the issues on the console. It's very "quick and dirty" but it found the issues for me.

class Program
{
    static void Main(string[] args)
    {
        if (args != null && args.Any())
        {
            foreach (var s in args)
            {
                Console.WriteLine("Checking " + s);
                DirectoryInfo dir = new DirectoryInfo(s);
                var files = dir.GetFiles("*.csproj", SearchOption.AllDirectories);

                var projects = files.Select(x => new Project(x)).ToList();

                var grouped = projects.GroupBy(x => x.TargetFrameworkVersion);
                if(grouped.Count()>1)
                {
                    Console.WriteLine("Solution contains multiple versions of Target Frameworks, this may cause duplicate assemblies in R# cache");
                    foreach (var group in grouped)
                    {
                        Console.WriteLine(group.Key);
                        foreach (var project in group)
                        {
                            Console.WriteLine(project.AssemblyName);
                        }
                    }
                }

                //loop through for debugging
                foreach (var project in projects)
                {
                    foreach (var reference in project.References)
                    {
                        foreach (var checkProject in projects)
                        {
                            if (checkProject.AssemblyName == reference)
                            {
                                Console.WriteLine("Reference in" + project.FileName + " referencing " +
                                                  reference+" that should be a ProjectReference, this may cause duplicate entries in R# Cache");
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Complete");
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("You must provide a path to scan for csproj files");
        }
    }


}

public class Project
{
    public string FileName { get; set; }
    public string AssemblyName { get; set; }
    public string ProjectGuid { get; set; }
    public string TargetFrameworkVersion { get; set; }
    public IList<string> References { get; set; }
    private FileInfo _file;
    private XmlDocument _document;
    private XmlNamespaceManager _namespaceManager;

    public Project(FileInfo file)
    {
        _file = file;

        FileName = _file.FullName;

        _document = new XmlDocument();
        _document.Load(_file.FullName);

        _namespaceManager = new XmlNamespaceManager(_document.NameTable);
        _namespaceManager.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");

        var projectGuidNode = _document.SelectSingleNode("//msbld:ProjectGuid", _namespaceManager);
        ProjectGuid = projectGuidNode.InnerText;

        var assemblyNameNode = _document.SelectSingleNode("//msbld:AssemblyName", _namespaceManager);
        AssemblyName = assemblyNameNode.InnerText;

        var targetFrameworkNode = _document.SelectSingleNode("//msbld:TargetFrameworkVersion", _namespaceManager);
        TargetFrameworkVersion = targetFrameworkNode.InnerText;

        References = new List<string>();
        var referenceNodes = _document.SelectNodes("//msbld:Reference", _namespaceManager);
        foreach (var node in referenceNodes)
        {
            var element = (XmlElement) node;

            //file references
            if (element.HasChildNodes)
            {
                foreach (var child in element.ChildNodes)
                {
                    var childElement = (XmlElement)child;
                    if (childElement.Name == "HintPath")
                    {
                        var value = childElement.InnerText;
                        value = value.Substring(value.LastIndexOf("\\") + 1);
                        value = value.Replace(".dll", "");
                        References.Add(value);
                    }
                }
            }
            //gac references
            else
            {
                foreach (var attr in element.Attributes)
                {
                    var attribute = (XmlAttribute)attr;
                    if (attribute.Name == "Include")
                    {
                        var value = attribute.Value;
                        string reference = value;
                        if (value.Contains(','))
                        {
                            reference = value.Substring(0, value.IndexOf(','));
                        }
                        References.Add(reference);
                        break;
                    }
                }
            }


        }

    }
}
Brook
  • 5,949
  • 3
  • 31
  • 45
  • That code works.. However easier and faster for me was to do a simple search of *TargetFrameworkVersion* in all my *.csproj and quickly look through all occurrences. – Vladimirs Mar 19 '15 at 17:13