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
    {

    }
}
10
  • What is the namespace inside the class file itself? Commented Jan 11, 2017 at 0:59
  • Provide more information. Did you referenced that project? your project.js (or csproj if you are on vs2017), platforms you target etc. Commented Jan 11, 2017 at 1: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. Commented Jan 11, 2017 at 1:01
  • @Steve The namespaces match the folder structure you can see. Commented Jan 11, 2017 at 1: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? Did they successfully compile? Commented Jan 11, 2017 at 1:03

2 Answers 2

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")]
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.