0

I have a few folders inside my interfaces sub project. I can "see" two of them, but not the third. The reference is obviously added, otherwise I wouldn't be able to "see" or access any of the namespaces inside the sub project.

Any ideas what could be wrong here?

missing namespace reference

File ProjectContext.cs from project Project.Data needs to inherit an interface from another project Project.Interfaces.

Project.Data has a reference to Project.Interfaces.

The interface is located in Project.Interfaces\Data\IProjectContext.cs.

For whatever reason the Data directory is not visible in the autocomplete provided by Visual Studio. I am not able to access the Project.Interfaces.Data namespace.

project.json from Project.Data

{
  "version": "1.0.0-*",

  "dependencies": {
"Project.Interfaces": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"NETStandard.Library": "1.6.1",
"System.ComponentModel.Annotations": "4.3.0"
},

"frameworks": {
"netstandard1.6": {
  "imports": "dnxcore50"
}
}
}

ProjectContext.cs

namespace Project.Data
{
public class ProjectContext : DbContext
{
    public ProjectContext(DbContextOptions<ProjectContext> options) : base(options)
    {
        Database.EnsureCreated();
    }

}
}

IProjectContext.cs

namespace Project.Interfaces.Data
{
    interface IProjectContext
    {

    }
}
Burning Hippo
  • 787
  • 1
  • 20
  • 47
  • What is the namespace inside the class file itself? – Steve Jan 11 '17 at 00:59
  • Provide more information. Did you referenced that project? your project.js (or csproj if you are on vs2017), platforms you target etc. – Tseng Jan 11 '17 at 01:00
  • @Tseng You can see that I have autocomplete for two of those folders (Services and Repositories) so that means that yes, I have made a reference to project Interfaces from project Data. – Burning Hippo Jan 11 '17 at 01:01
  • @Steve The namespaces match the folder structure you can see. – Burning Hippo Jan 11 '17 at 01:02
  • A folder is not a namespace. Are you certain there are classes within the `Data` folder that are in the right namespace? Are those classes [included in the project](http://stackoverflow.com/questions/1352554/undo-vs-exclude-from-project)? Did they successfully compile? – John Wu Jan 11 '17 at 01:03
  • @BurningHippo can you post a screenshot or code from one of the classes you are trying to reference? – Steve Jan 11 '17 at 01:04
  • I think one/more file that you are trying to reference is deleted or The file being referenced has been renamed. – Vishwa Ratna Jan 11 '17 at 01:05
  • The project builds with no errors. I will update the question with the files in question. – Burning Hippo Jan 11 '17 at 01:06
  • @BurningHippo: That wasn't my question. i.e. you have two projects (interfaces and repositories) so its not clear where the name space is defined. My question is still: Have you referenced all required projects. w/o project.json/*.csproj we cant be certain – Tseng Jan 11 '17 at 01:10
  • @Tseng I added my project.json file, too. – Burning Hippo Jan 11 '17 at 01:18

2 Answers2

3

It seems that you have the impression that the folder structure defines the namespaces. They are in fact totally irrelevant (although it's a good convention to follow). Check your files inside the folders that are missing, and change the namespace definition in the code, presumably you want this to match your folder structure.

Another thing to look for is whether the classes /interfaces are public.

David S.
  • 5,965
  • 2
  • 40
  • 77
3

The default access modifier in c# is internal. Since your IProjectContext interface doesn't have a modifier, it is assumed to be internal and so not available to other projects.

Make the interface public and you will be able to reference it in other projects.

namespace Project.Interfaces.Data
{
    public interface IProjectContext
    {

    }
}

If you want the interface to be internal for API reasons, you can add an InternalsVisibleTo line to the AssemblyInfo.cs file in your Project.Interfaces project:

[assembly: InternalsVisibleTo("Project.Data")]
Steve
  • 9,335
  • 10
  • 49
  • 81