1

I am new to MVC and not sure what I am doing wrong.

I have a solution with two projects in it. One is a C# library class project and the other is an ASP.NET MVC project.

The class library project is for holding a class used by the MVC project.

But I can't get the MVC Project to "see" the class project.

I have added a reference to the class library project in the MVC project, but when I try using MVC.Class in the MVC code file I can't access the files in the class project -- it is gray out and doesn't see the class project.

Can someone please tell me what I am doing wrong. Thanks for the help.

David Tansey
  • 5,813
  • 4
  • 35
  • 51
  • 1
    Unclear which reference you are adding to where at least to me. If you are referencing C# project into MVC project you can use it in your MVC project but your C# project cannot use MVC. Can only reference one way – Hasta Tamang Feb 22 '19 at 18:41
  • I am referencing the Class project from the MVC project. I found out one thing that doesn't make sense to me. When I created the Class project a Class1.cs file was added. If I don't delete that file then the reference works but if I delete the file then the reference does not work. I don't get it. – Tom Mauldin Feb 22 '19 at 19:26
  • Ok, then all the class,interface etc that is exposed can be used by your MVC project. – Hasta Tamang Feb 22 '19 at 19:36
  • Are you using Class1.cs in MVC project? and when you delete that class it wont work? or the whole reference to other class in C# project also do not work? I am confused now lol – Hasta Tamang Feb 22 '19 at 19:39
  • No I am not using the Class1.cs, it is add automatically when I add the project to the solution. As long as that Class1.cs is in the project a reference in the MVC ie "Using MVC.Class;" works fine but when I delete the Class1.cs from the Class project the connection is broken between the MVC project and the Class project. I don't understand why this is happening. – Tom Mauldin Feb 22 '19 at 20:50
  • how do u know connection is broken – Hasta Tamang Feb 22 '19 at 20:54
  • The using statement is grayed out and the file that was being used now has an red underline with the error message missing reference. – Tom Mauldin Feb 22 '19 at 21:06
  • Compare the `namespace` that is specified on `Class1.cs` with the `namespace` value that is specified on the other CS file in that project -- I expect you will find that they do NOT match. If this is the case, change the `namespace` value to match what shows in `Class1.cs`. – David Tansey Feb 22 '19 at 21:10
  • In your MVC project under References as long as there is a reference to your C# class project, you have a reference and can use all public class in that project – Hasta Tamang Feb 22 '19 at 21:17
  • @HastaTamang ...as long as you also have a proper `using` statement – David Tansey Feb 22 '19 at 21:22
  • @DavidTansey correct – Hasta Tamang Feb 22 '19 at 21:22
  • 1
    Ok Thank you very much you pointed me in the right direction. It wasn't the name space. It was the constructor. When I added a new class the constructor was not made public so change it to pubic and everything works. Thanks again for the help – Tom Mauldin Feb 22 '19 at 21:33
  • Welcome to StackOverflow #SOReadyToHelp – David Tansey Feb 22 '19 at 21:38

0 Answers0