I have been re-factoring one of my old MSSQL Connection helper library and I got the following error:
Severity Code Description Project File Li
I received this same error in the following Linq statement regarding DailyReport. The problem was that DailyReport had no default constructor. Apparently, it instantiates the object before populating the properties.
var sums = reports
.GroupBy(r => r.CountryRegion)
.Select(cr => new DailyReport
{
CountryRegion = cr.Key,
ProvinceState = "All",
RecordDate = cr.First().RecordDate,
Confirmed = cr.Sum(c => c.Confirmed),
Recovered = cr.Sum(c => c.Recovered),
Deaths = cr.Sum(c => c.Deaths)
});
In the constructor of
public class ErrorEventArg : EventArgs
You have to add "base" as follows:
public ErrorEventArg(string errorMsg, string lastQuery) : base (string errorMsg, string lastQuery)
{
ErrorMsg = errorMsg;
LastQuery = lastQuery;
}
That solved it for me
I got the same error but it was due to me not creating a default constructor. If you haven't already tried that, create the default constructor like this:
public TestClass() {
}
You have a constructor which takes 2 parameters. You should write something like:
new ErrorEventArg(errorMsv, lastQuery)
It's less code and easier to read.
EDIT
Or, in order for your way to work, you can try writing a default constructor for ErrorEventArg which would have no parameters, like this:
public ErrorEventArg() {}
I got this error when one of my properties that was required for the constructor was not public. Make sure all the parameters in the constructor go to properties that are public if this is the case:
using statements namespace someNamespace
public class ExampleClass {
//Properties - one is not visible to the class calling the constructor
public string Property1 { get; set; }
string Property2 { get; set; }
//Constructor
public ExampleClass(string property1, string property2)
{
this.Property1 = property1;
this.Property2 = property2; //this caused that error for me
}
}