I have a simple generic class as follows:
public class DataResponse<T> where T : new()
{
public DataResponse()
{
this.Data = new List<T>();
IsSuccessful = true;
}
public bool IsSuccessful { get; set; }
public string[] ErrorMessages { get; set; }
public List<T> Data { get; set; }
}
It works just fine for every custom type I use, however in once instance I have a collection of data that is one field. Rather than make custom class with one field I would make the type string. Doing so however returns the error:
var response = new DataResponse<String>();
'string' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'DataResponse'
UPDATE I had added the where T : new() in response to encountering the problem originally. Removing it solved it because it caused the IDE to highlight the correct line that was actually giving me the problem. The line causing the error was to a method that does have the new() constraint.
Apparently its an entirely different call on a method
System.Stringdoes not have a parameterless constructor. Where do you see one? - O. R. Mapper