CBO.FillCollection抛出"没有为此对象定义的无参数构造函数".错误

Mat*_*att 3 c# dotnetnuke idatareader dataprovider

我正在尝试从另一个方法返回的IDataReader中填充一个集合...由于某种原因,它不断抛出"为此对象定义的无参数构造函数".此行的错误:

List<string> names = CBO.FillCollection<string>(DataProvider.Instance().ExecuteReader("getNames", new SqlParameter("UserId", 1)));
Run Code Online (Sandbox Code Playgroud)

我已经尝试分离出参数,所以事情会分开初始化,直到我有了这个:

List<string> names = CBO.FillCollection<string>(nameDataReader);
Run Code Online (Sandbox Code Playgroud)

我在同一条线上仍然收到错误.

有任何想法吗?

Dav*_*emp 5

消息中的线索.System.String没有无参数构造函数,因此无法使用Activator.CreateInstance创建它,这通常用于动态创建对象.

编辑:解决方案是直接使用阅读器:

var strings = new List<string>();
using(var reader = DataProvider.Instance().ExecuteReader("getNames", new SqlParameter("UserId", 1)))
{
    while(reader.Read()) 
        strings.Add(reader[0] as string);
}
Run Code Online (Sandbox Code Playgroud)