简体   繁体   中英

No parameterless constructor defined for this object ASP.NET Website

I am getting error anyone can help me please. I'm using dotnet framework 4 with linq to sql below is the stack trace

No parameterless constructor defined for this object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

 [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

LINQDataContext.Designer.cs file is auto generated, don't change it, but create partial class in separate file with not parameterized constructor, for example:

public partial class MyDataContext : System.Data.Linq.DataContext
{
    public MyDataContext() 
        :base( ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString, mappingSource)
    {

    }
}

Issues have been resolved. I just create a parameterless constructor In LINQDataContext.Designer.cs

public ChallanTemplateDataContext(): 
  base(Util.connectionStr, mappingSource)

{

  OnCreated();

}

The error is self explanatory. You might have created a class like that. You just need to add a parameterless constructor in it. See example below:

public class cls
{
   public cls ()
   {
   }
   // your other parameterized constructors
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM