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 ofClone(). That requires a public parameterless constructor in the default usage. Otherwise it throws aMissingMethodException.Update: your update showing the stack-trace confirms this.
I suspect you can fix this by overriding the
CreateInstancemethod: