I have a library in which a protected method is there whose definition is as below :
public class InvokeCalc : IInvokeCalc
{
protected InvokeCalc(OtherClass comm);
public OtherClass();
}
I have added this library as reference in my .net core 3.1 console application.
This is what I have written :
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
SampleDAL dal = new SampleDAL();
dal.Trigger();
}
}
public class SampleDAL
{
IInvokeCalc app = null;
public async void Trigger()
{
OtherClass comm = new OtherClass();
app = new InvokeCalc(comm); // error
Console.ReadLine();
}
}
This code throws an error saying :
InvokeCalc.InvokeCalc(string) is not accessible due to its protection level.
I have seen in some other answers that if we inherit the InvokeCalc class , we can use its protected methods.
SO for that I have changed the definition of SampleDAL to as below :
public class SampleDAL : InvokeCalc // Inherited InvokeCalc class
{
IInvokeCalc app = null;
public async void Trigger()
{
OtherClass comm = new OtherClass();
app = new InvokeCalc(comm);
Console.ReadLine();
}
}
Doing like this giving an additional error :
InvokeCalc doesnt contain a constructor that takes 0 arguments.
Now I'm not sure on how to proceed further, any guidance in this case would be very helpful.