Reputation: 11
Trying to explain this very concisely
library.class
does not contain a constructor that takes a single argument.
If I create an object without a parameter the following error line is created:
library.class.constructor(string)
is inaccessible due to it's protection level.
I am not able to find a solution to this problem, I am providing my essential code below, if anyone can take a look and gauge what mistake is happening here, that would be really awesome:
abstract class EmployeeBase
{
private string empNumber;
public EmployeeBase(string CurrentEmployeeNumber) { empNumber = CurrentEmployeeNumber;}
......
class EmployeeExempt : EmployeeBase
{
public EmployeeExempt(string CurrentEmployeeNumber) : base(CurrentEmployeeNumber)
{ }
........
EmployeeExempt emp1 = new EmployeeExempt("1000");
This I believe is the core of my program, hopefully somebody can spot out the mistake that is happening here
Upvotes: 1
Views: 354
Reputation: 32094
You should explicitly declare both your base class and your derived class as public
. The default accessibility for classes is internal
so both of these classes are inaccessible from your main method. They are only accessible from within your class library project.
Upvotes: 2
Reputation: 7282
Both of your classes are being declared private. Prefix the class names with public or if they are intended to be in the same assembly perhaps internal.
Upvotes: 0
Reputation: 1500165
You should be getting three error messages:
Test.cs(7,9): error CS0122: 'EmployeeExempt' is inaccessible due to its
protection level
Test.cs(7,35): error CS0122: 'EmployeeExempt' is inaccessible due to its
protection level
Test.cs(7,31): error CS1729: 'EmployeeExempt' does not contain a constructor
that takes 1 arguments
The first two should make the problem pretty clear - as the other answers have said, EmployeeBase and EmployeeExempt are both internal classes (the default accessibility for non-nested types), which means they're only accessible within the same assembly. The class containing the Main method is in a different assembly, so you don't have access to them.
Just make them public.
I'll admit that the last error message is slightly misleading, but you should have looked at all the error messages rather than just that one - the first two should have given you enough hints about what was going on.
Upvotes: 1
Reputation: 174299
The only problem I see, is that EmployeeExempt
is internal
and not public
, but that doesn't match the error message...
I assume, you haven't shown us all relevant code, or the code really is slightly different from what you showed.
Upvotes: 0
Reputation: 2868
The string in the base class EmployeeBase is private . Try making it public .
Upvotes: -1