none
Public class, derived from an internal class RRS feed

  • Question

  • I have a class library which defines a few public classes. All of these classes have shared functionality, which is defined in a base class from which they are all derived. However, this functionality should only be available within the class library, and not by any other external code. For this reason, I specify the class as internal.

    When I attempted to compile the code, I got the error;

    Inconsistent accessibility: base class 'HTS.Database.Dbo<int>' is less accessible than class 'HTS.Database.StaffDetails'

    Dbo is the internal class. StaffDetails is the public class.

    Normally I would understand this error, however in this case I do not see why it should be a problem. The Dbo class consists entirely of internal properties and constructors, and private fields which, from an external point of view won't make any semantic changes to the StaffDetails class.

    Hopefully that makes sense? Can someone explain why this is a problem?

    Thanks


    Wednesday, October 25, 2006 6:41 PM

Answers

  • Guessing a bit: I think this requirement is imposed by Reflection.  It promises you can fully reconstruct the type hierarchy of a class from the meta-data of an assembly.  Having the base class of a public class declared as internal would prevent that.
    Wednesday, October 25, 2006 10:10 PM
    Moderator

All replies

  • Hi Barguast

    What happens here is , when you instantiate the derived class it creates the object of its parent in the memory which unfortunately

    you are not exposing outside the project. I feel this is the reason why you are getting the compilation error.

    Thanks,

    Wednesday, October 25, 2006 6:50 PM
  • That may be it, though the instantiation of the derived class would be done inside the public classes' constructor which, given that the public classes are declared inside the class library alongside the internal base class, shouldn't be an issue as far as I'm aware...?

    Thanks for your reply.
    Wednesday, October 25, 2006 6:53 PM
  • Guessing a bit: I think this requirement is imposed by Reflection.  It promises you can fully reconstruct the type hierarchy of a class from the meta-data of an assembly.  Having the base class of a public class declared as internal would prevent that.
    Wednesday, October 25, 2006 10:10 PM
    Moderator
  • Well, I'm just pleased the answer isn't so obvious. :p

    It's no big deal to declare the class as public since it is abstract with internal constructors and members anyway - it still can't be used in any true sense outside of the class library. It just would've been nice to hide it. Oh well.

    Thanks for all your help.
    Thursday, October 26, 2006 9:01 AM