A circular reference was detected while serializing an object of type and stackoverflow exception

0
 [HttpPost]
    public JsonResult GetallData(int id)
    {
        MultipleViewModel model = new MultipleViewModel();
        List<InformationSecurityData> iso = db.InformationSecurityDatas.Where(x => x.Supplier_ID == id).ToList();
        List<SurveyForm> tender = db.SurveyForms.Where(x => x.Supplier_ID == id ).ToList();
        List<ProcurementData> procurement = db.ProcurementDatas.Where(x => x.Supplier_ID == id ).ToList();
        List<Supplier> supp = db.Suppliers.Where(x => x.Supplier_ID == id).ToList();

        model.Inf_Sec_Dat = iso;
        model.Proc_Dat = procurement;
        model.Tender_Dat = tender;
        model.Supp_dat = supp;

        //string json = JsonConvert.SerializeObject(model, Formatting.Indented,
        //new JsonSerializerSettings
        //{
          //  ReferenceLoopHandling = ReferenceLoopHandling.Serialize
        //});

        return Json(model, JsonRequestBehavior.AllowGet);
    }

controller function to get 4 table as json object

  <script type="text/javascript">
        iso_data = [];
        tender_data = [];


        $(document).ready(function () {
            $("#GetallData").click(function () {
                var id = $("#id").val();
                $.ajax({
                    url: '/Dashboard/GetallData/',
                    data: {id:id},
                    type: 'POST',
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        alert("success ");

                        $.each(data.Inf_Sec_Dat, function (i, item) {
                            iso_data.push(item.Total_Score);
                        });
                        bindChart(iso_data);
                        $.each(data.Tender_Dat, function (i, item) {
                            tender_data.push(item.Total_Score);
                        });
                        bindChart2(tender_data);
                        //bindChart3(tender_data);
                    },
                    error: function (response) {
                        alert("error_tender" + response);
                    }
                });
            });

ajax in view

public class MultipleViewModel
{
    public List<InformationSecurityData> Inf_Sec_Dat { get; set; }
    public List<ProcurementData> Proc_Dat { get; set; }
    public List<SurveyForm> Tender_Dat { get; set; }
    public List<Supplier> Supp_dat { get; set; }

}

multiple view model to get complex data

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please 
visit
  https://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit 
http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" 
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, 
EntityFramework, Version=6.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <!--
    For a description of web.config changes see 
http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5.2" />
      </system.Web>
  -->
   <system.web>
    <authentication mode="Forms">
      <forms cookieless="UseCookies" loginUrl="~/user/login" 
slidingExpiration="true" />
    </authentication>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" 
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, 
Microsoft.AI.Web" />
    </httpModules>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" 
publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" 
/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" 
publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" 
/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" 
/>
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" 
newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" 
publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" 
/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" 
publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" 
/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" 
publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" 
/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" 
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, 
 Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
  /system.codedom>
  <entityFramework>
   <defaultConnectionFactory 
type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 
EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" 
type="System.Data.Entity.SqlServer.SqlProviderServices, 
EntityFramework.SqlServer" />
    </providers>
   </entityFramework>
  <connectionStrings>
        <add name="SupplierEvaluationEntities1" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=&quot;C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\SupplierEvaluation.mdf&quot;;integrated security=True;multipleactiveresultsets=True;connect timeout=30;application name=EntityFramework'" providerName="System.Data.EntityClient" />
     </connectionStrings>
</configuration>

web.config

and that is my error

A circular reference was detected while serializing an object of type 'SupplierEvaluation.Models.InformationSecurityData'. 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.InvalidOperationException: A circular reference was detected while serializing an object of type 'SupplierEvaluation.Models.InformationSecurityData'.

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

when I open commented lines i controller function then I got this exception System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown.

so what should I do to fix this error

json
asp.net-mvc
asked on Stack Overflow May 8, 2018 by ysrsy • edited May 8, 2018 by ysrsy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0