i have the following class that inherits from DataTable:
public class ExcelStaticDataTable : DataTable
{
public List<ExcelStaticDataTable> SubTables { get; set; }
public ExcelStaticDataTable(string tableName): base(tableName)
{
SubTables = new List<ExcelStaticDataTable>();
}
}
Do you know why im getting a MissingMethodException "parameterless constructor defined for this object" when i do the following:
ExcelStaticDataTable table=new ExcelStaticDataTable("table1");
table.Clone();
Both pieces of codes are in a different dll's just for clarify. and here the stacktrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Data.DataTable.CreateInstance()
at System.Data.DataTable.Clone(DataSet cloneDS)
at System.Data.DataTable.Clone()
at System.Data.DataTable.Copy()
at ..........cs:line 35
Thanks.
I suspect the other code is using object newObj = Activator.CreateInstance(GetType()); as part of Clone(). That requires a public parameterless constructor in the default usage. Otherwise it throws a MissingMethodException.
Update: your update showing the stack-trace confirms this.
I suspect you can fix this by overriding the CreateInstance method:
protected override DataTable CreateInstance()
{
return new ExcelStaticDataTable(TableName);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With