0

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
1
  • Could you please post code behind code of you aspx page.
    – Ricky
    Commented Jun 14, 2014 at 5:15

3 Answers 3

1

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)
    {

    }
}
0

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

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

{

  OnCreated();

}

1
  • Great. All you needed is the right direction and see, you yourself solved the problem. Cheers!
    – Ricky
    Commented Jun 14, 2014 at 5:42
-1

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
}
3
  • Your answer is not as clear as it could be: the OP has a class that already has a parameterised constructor but they also require a default parameterless one probably due to serialisation.
    – slugster
    Commented Jun 14, 2014 at 5:08
  • I just assign LinqDataSource to Gridview when I debug the code there is no exception at all but after the page load error page has been displayed.
    – Numan
    Commented Jun 14, 2014 at 5:08
  • @slugster: Agree. We can't figure out the exact problem by looking at the stacktrace. Can we? So its the closest solution to OP's problem that I can suggest.
    – Ricky
    Commented Jun 14, 2014 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.