我收到任何人可以帮助我的错误。我使用带有linq到sql的dotnet框架4 下面是堆栈跟踪
No parameterless constructor defined for this object.
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.MissingMethodException:没有为此对象定义无参数构造函数。
来源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈追踪:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
System.Web.HttpRuntime.FastCreatePublicInstance(Type type) +78
System.Web.UI.WebControls.LinqDataSourceView.CreateContext(Type contextType) +6
System.Web.UI.WebControls.LinqDataSourceView.CreateContextAndTable(DataSourceOperation operation) +799
System.Web.UI.WebControls.LinqDataSourceView.CreateContextAndTableForSelect() +137
System.Web.UI.WebControls.LinqDataSourceView.CreateContext(DataSourceOperation operation) +12
System.Web.UI.WebControls.ContextDataSourceView.GetSource(QueryContext context) +20
System.Web.UI.WebControls.LinqDataSourceView.GetSource(QueryContext context) +325
System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +63
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446
答案 0 :(得分:1)
LINQDataContext.Designer.cs文件是自动生成的,不要更改它,而是使用非参数化构造函数在单独的文件中创建部分类,例如:
public partial class MyDataContext : System.Data.Linq.DataContext
{
public MyDataContext()
:base( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString, mappingSource)
{
}
}
答案 1 :(得分:0)
问题已得到解决。我只是在LINQDataContext.Designer.cs中创建一个无参数构造函数
public ChallanTemplateDataContext():
base(Util.connectionStr, mappingSource)
{
OnCreated();
}
答案 2 :(得分:-1)
错误是不言自明的。您可能已经创建了这样的类。您只需要在其中添加无参数构造函数。见下面的例子:
public class cls
{
public cls ()
{
}
// your other parameterized constructors
}