Search code examples
c#visual-studiomstest

I added a reference to the main project, but the testing project still doesn't see the classes of main


My solution has a project that contains all the program logic. I created a unit test project, added a reference to the main project, but still can't use classes from it to create tests.

My code:

namespace Program
{
    public class Class
    {
        public Class()
        {
        ///
        }

        public int foo()
        {
        ///
        }
    }
}

My tests code:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Program; // cs0246

namespace ProgramTests
{
    [TestClass]
    public class ClassTests
    {
        [TestMethod]
        public void foo_()
        {
            // Arrange
            Class testClass; // this code also have cs0246 error
            // Act

            // Assert
        }
    }
}

In this code, using Program; underlined in red with cs0246 error. But namespace ProgramTests have the reference to Program (there is a checkmark in the reference manager). How can i fix it?

Image of Solution Explorer enter image description here


Solution

  • Please, check the framework version you are using. Maybe Tests library has framework which is no compatible with ClassLib Framework