Ian Warburton
Ian Warburton

Reputation: 15666

ReSharper: Namespace does not correspond to file location

I renamed a folder and updated my namespace declarations, but ReSharper 6 claims that the namespace should be a reflection of how it was before the rename. Where is it storing the file location data?

Upvotes: 43

Views: 22719

Answers (6)

IllusiveBrian
IllusiveBrian

Reputation: 3204

If you're using JetBrains Rider, go to the Solution Explorer and right click on the csproj file, then properties in the context menu. In my case the Assembly Name was already updated but "Root Namespace" wasn't, updating Root Namespace allowed JetBrains to automatically update all namespaces.

Upvotes: 0

clickatwill
clickatwill

Reputation: 970

Check to make sure your assembly name matches your new namespace. If you've changed your folder structure to match your new namespace, you may still see the ReSharper alert until you update the project properties.

Upvotes: 55

Sameera R.
Sameera R.

Reputation: 4572

As delliottg's comment says, in Visual Studio, go to

Project > [project name] Properties > Application

and change "Assembly name" as well as "Default namespace".

Upvotes: 17

Goodies
Goodies

Reputation: 2069

I use Resharper 2019.3.2 in VS 2019 vs 16.5.2 and I had similar issues.

When developing, I first work out my namespace hierarchy in a single project, then split the project in seperate class libraries. In the first stage, it is convenient to always let the subdirectory correspond to the namespace.

For example, my prototype MeshTools.dll project currently contains:

 Meshtools ........................ 3 cs-files in \MeshTools
   MeshTools.HeightField .......... 2 cs-files in \MeshTools\HeightField
   MeshTools.VectorTools .......... 3 cs-files in \MeshTools\VectorTools

The above answers all assume one single namespace per project. Renaming directories manually may confuse Resharper and that can be repaired by setting the default assembly in the .csproj file to the proper namespace. Thanks for the tip.

However in my case, I have several namespaces in a single project, with each namespace in a Solution directory corresponding to a real directory. Setting the default assembly "Meshtools" does not affect ReSharper behaviour for HeightField and VectorTools, when things have gone wrong with the renaming.

I googled this issue and came by https://www.jetbrains.com/help/resharper/Refactorings__Adjust_Namespaces.html#

It turns out there is a right-click option on a Solution Directory -> Properties. You will find an option to decide, if the Solution Directory is a NameSpace provider or not. When something has gone wrong, Visual studio will reset the field to False. Set it back to True and Resharper will correctly refactor namespace or file location when needed..

Upvotes: 1

Root namespace is needed to be changed as following.

enter image description here

Upvotes: 7

MarkG
MarkG

Reputation: 1869

I also had this problem with a folder/namespace and none of the above steps fixed it.

In my case I had to do this in Visual Studio:

  • Right-click the "problem" folder in the solution explorer to open the properties
  • Ensure the "Namespace Provider" is set to true

This fixed the ReSharper issue for me and I was able to adjust namespaces as normal.

Upvotes: 13

Related Questions