0

I have an internal class in MyProject. I have another internal class in my UnitTestProject. I want to inherit MyProject.internalClass from UnitTestProject.internalClass. But I can't inherit. Here is my code.

namespace MyProject.Data
{
    internal class BaseClass
    {

    }
}


namespace MyUnitTests.Data
{
    internal class TestClass: BaseClass
    {

    }
}

I add reference MyProject.dll in UnitTests project. But I still can't inherit. I am not sure the way I'm doing is right or wrong. Please give me any suggestion?

PPPA
  • 25
  • 7

3 Answers3

0

Internal means the class is only visible for the assembly itself. Change BaseClass to public.

Since we seem to be handling testing here also look into InternalsVisibleTo to keep your base class internal but allow for explicit (e.g. testing) assemblies see it.

LosManos
  • 7,195
  • 6
  • 56
  • 107
0

See InternalsVisibleToAttribute. You should put this attribute into AssemblyInfo.cs for the MyProject assembly:

[assembly:InternalsVisibleTo("MyUnitTests")]
Dennis
  • 37,026
  • 10
  • 82
  • 150
  • Thank you so much. Actually, I'm following the existing old project that was done by senior who has gone. I found to use InternalsVisibleToAttribute by searching in google. But I was getting trouble finding that attribute on top of the class name without knowing that should be written in AssemblyInfo.cs. – PPPA Oct 02 '14 at 07:33
0

Internal classes are only visible within the assembly they are defined. So it is by default not possible to access an internal class within one assembly from another assembly.

To do so you can use the InternalsVisibleToAttribute.

Oliver
  • 1,507
  • 1
  • 12
  • 23