A circular reference was detected while serializing

Posts   
 
    
hotmail
User
Posts: 47
Joined: 06-Feb-2013
# Posted on: 24-Mar-2015 13:05:49   

Using ASP.NET MVC 5, .NET 4.5, LLBL 4.2 latest, SQL Server 2014 and Telerik UI for ASP.NET MVC

We have just started an ASP.NET MVC 5 application. When i bind either Typed View or EntityCollection to Telerik Kendo DropDownList, i am getting an exception. I contacted Telerik support but couldn't get much help.

They said....

Based on the given information and stack trace, I can conclude that there is a circular reference in the bound model and built-in serializer cannot serialize it.

My Typed View is based on Table Valued Function, I am not sure how there would be a circular reference in either typed view or entity collection.

Can i get some help in resolving this issue?

Thanks


        public TfStringSplitResultTypedView GetStringSplitTv()
        {
            var filter = new RelationPredicateBucket(new DynamicRelation(TvfCallFactory.TfStringSplit("Tbl", "a,b,c,d", ",")));
            filter.Relations.SelectListAlias = "Tbl";
            TfStringSplitResultTypedView tv = new TfStringSplitResultTypedView();
            using (DataAccessAdapter adapter =new DataAccessAdapter())
            {
                adapter.FetchTypedView(tv, filter, true);
                adapter.CloseConnection();
            }
            return tv;
        }

SQL Side


SELECT * FROM dbo.[TfStringSplit]('a,b,c,d',',')

----Result----
SN   Item
1   a
2   b
3   c
4   d


here is my controller that passes model to the view


publicActionResult Index()
{
    IPersonService ps = newPersonService();
    RegisterModel rm = newRegisterModel();
    rm.CurrentPerson=ps.GetPersonEntity(1);
    //Get Typed View
    rm.TvString = ps.GetStringSplitTv();
    //Get RoomType Entity Collection
    rm.RoomTypeCollection = ps.GetRoomType();
    returnView(rm);
}

here is the RegisterModel class


publicclassRegisterModel
{
    publicPersonEntity CurrentPerson { get; set; }
    publicTfStringSplitResultTypedView TvString = newTfStringSplitResultTypedView();
    publicEntityCollection<RoomTypeEntity> RoomTypeCollection = newEntityCollection<RoomTypeEntity>();
}

here is my view that has model, but now i am trying to use Typed View for drop down.


@model Hotel.Web.Models.RegisterModel
@{
    ViewBag.Title = "Home Page";
}
@Model.CurrentPerson.FirstName
@Model.TvString.Count
@Model.RoomTypeCollection.Count

@{
    <ul>
        @for (int i = 0; i < Model.TvString.Count; i++)
        {
            <li>@Model.TvString[i].Item</li>
        }
    </ul>
}
@{
    <ul>
        @for (int i = 0; i < Model.RoomTypeCollection.Count; i++)
        {
            <li>@Model.RoomTypeCollection[i].RoomType</li>
        }
    </ul>
}

<divclass="demo-section"style="width: 250px;">
    <h2>Items</h2>
    @(Html.Kendo().DropDownList()
          .Name("ModelItem")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("Item")
          .DataValueField("SN")
          .BindTo(Model.TvString)
    )
</div>

Here is the exception


Line 51: <div class="demo-section" style="width: 250px;">
Line 52:     <h2>Items</h2>
Line 53:     @(Html.Kendo().DropDownList()
Line 54:           .Name("ModelItem")
Line 55:           .HtmlAttributes(new { style = "width: 250px" })

Stack Trace

[InvalidOperationException: A circular reference was detected while serializing an object of type 'Hotel.TypedViewClasses.TfStringSplitResultTypedView'.]
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2616
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +186
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2782
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +57
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +83
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +44
   Kendo.Mvc.Infrastructure.DefaultJavaScriptSerializer.Kendo.Mvc.Infrastructure.IJavaScriptSerializer.Serialize(Object ) +42
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +687
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.InitializeFor(String selector, String name, IDictionary`2 options) +165
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.Initialize(String id, String name, IDictionary`2 options) +87
   Kendo.Mvc.UI.DropDownList.WriteInitializationScript(TextWriter writer) +2273
   Kendo.Mvc.UI.WidgetBase.WriteHtml(HtmlTextWriter writer) +117
   Kendo.Mvc.UI.DropDownList.WriteHtml(HtmlTextWriter writer) +94
   Kendo.Mvc.UI.WidgetBase.ToHtmlString() +115
   Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString() +62
   System.Web.HttpUtility.HtmlEncode(Object value) +38
   System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) +47
   System.Web.WebPages.WebPageBase.Write(Object value) +53
   ASP._Page_Views_Home_Index_cshtml.Execute() in c:\Users\ga ca\Documents\Visual Studio 2013\Projects\HotelApplication\Hotel.Web\Views\Home\Index.cshtml:53
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +121
   System.Web.WebPages.StartPage.RunPage() +63
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +100
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


here is the same view when i bind it to Entity collection


@model Hotel.Web.Models.RegisterModel
@{
    ViewBag.Title = "Home Page";
}
@Model.CurrentPerson.FirstName
@Model.TvString.Count
@Model.RoomTypeCollection.Count
@{
    <ul>
        @for (int i = 0; i < Model.TvString.Count; i++)
        {
            <li>@Model.TvString[i].Item</li>
        }
    </ul>
}
@{
    <ul>
        @for (int i = 0; i < Model.RoomTypeCollection.Count; i++)
        {
            <li>@Model.RoomTypeCollection[i].RoomType</li>
        }
    </ul>
}

<div class="demo-section" style="width: 250px;">
    <h2>Items</h2>
    @(Html.Kendo().DropDownList()
          .Name("ModelRoomType")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("RoomType")
          .DataValueField("RoomTypeId")
          .BindTo(Model.RoomTypeCollection)
    )
</div> 

and here is the exception


Line 52:     <h2>Items</h2>
Line 53:     @(Html.Kendo().DropDownList()
Line 54:           .Name("ModelRoomType")
Line 55:           .HtmlAttributes(new { style = "width: 250px" })


[InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.]
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2616
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +186
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2782
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +186
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2782
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +819
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +186
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2782
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +57
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +83
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +44
   Kendo.Mvc.Infrastructure.DefaultJavaScriptSerializer.Kendo.Mvc.Infrastructure.IJavaScriptSerializer.Serialize(Object ) +42
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +687
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.InitializeFor(String selector, String name, IDictionary`2 options) +165
   Kendo.Mvc.Infrastructure.JavaScriptInitializer.Initialize(String id, String name, IDictionary`2 options) +87
   Kendo.Mvc.UI.DropDownList.WriteInitializationScript(TextWriter writer) +2273
   Kendo.Mvc.UI.WidgetBase.WriteHtml(HtmlTextWriter writer) +117
   Kendo.Mvc.UI.DropDownList.WriteHtml(HtmlTextWriter writer) +94
   Kendo.Mvc.UI.WidgetBase.ToHtmlString() +115
   Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString() +62
   System.Web.HttpUtility.HtmlEncode(Object value) +38
   System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) +47
   System.Web.WebPages.WebPageBase.Write(Object value) +53
   ASP._Page_Views_Home_Index_cshtml.Execute() in c:\Users\ga ca\Documents\Visual Studio 2013\Projects\HotelApplication\Hotel.Web\Views\Home\Index.cshtml:53
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +121
   System.Web.WebPages.StartPage.RunPage() +63
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +100
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Mar-2015 04:23:23   

Circular references can be avoided by configuring the json serialization. Check Frans' post where he configured the newtonsoft serializer. http://weblogs.asp.net/fbouma/how-to-make-asp-net-webapi-serialize-your-llblgen-pro-entities-to-json

Another solution is to use a ViewModel as described here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=22817

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-Mar-2015 09:00:12   

the typedview is a datatable, which might cause it, but then again, it's pretty odd as there are no external references in the typedview itself. If the json config doesn't help (it should, but say it doesn't) generate the typedview as a poco (v4.2 feature) as that gets rid of the datatable and whatever cyclic references it contains.

Frans Bouma | Lead developer LLBLGen Pro
hotmail
User
Posts: 47
Joined: 06-Feb-2013
# Posted on: 25-Mar-2015 18:27:13   

I followed both Fran's post on Web Api and Generating Typed Views as POCO and they both seem to work. Thanks

I still don't have solution on binding entity collection directly (.BindTo(Model.RoomTypeCollection ))

Following is the code sample that seem to work.

Here is my web api following http://weblogs.asp.net/fbouma/how-to-make-asp-net-webapi-serialize-your-llblgen-pro-entities-to-json


    public class DefaultController : ApiController
    {
        IPersonService ps = new PersonService();

        [Route("api/Default/GetStringSplit")]
        [HttpGet]
        public TfStringSplitResultTypedView GetStringSplit()
        {
            return this.ps.GetStringSplitTv();
        }
        [Route("api/Default/GetStringSplitPOCO")]
        [HttpGet]
        public IQueryable<TfStringSplitResult1Row> GetStringSplitPOCO()
        {
            return this.ps.GetStringSplitPOCO();
        }

        [Route("api/Default/GetRoomType")]
        [HttpGet]
        public EntityCollection<RoomTypeEntity> GetRoomType()
        {
            return this.ps.GetRoomType();
        }
    }

here is my new model with Typed View POCO


    public class RegisterModel
    {
        public PersonEntity CurrentPerson { get; set; }
        public TfStringSplitResultTypedView TvString = new TfStringSplitResultTypedView();
        public EntityCollection<RoomTypeEntity> RoomTypeCollection = new EntityCollection<RoomTypeEntity>();
        public IQueryable<TfStringSplitResult1Row> NewTestItem;
    }

Controller that passes model to view,


        public ActionResult Index()
        {
            IPersonService ps = new PersonService();
            RegisterModel rm = new RegisterModel();
            rm.CurrentPerson=ps.GetPersonEntity(1);
            //Get Typed View
            rm.TvString = ps.GetStringSplitTv();
            //Get RoomType Entity Collection
            rm.RoomTypeCollection = ps.GetRoomType();
            rm.NewTestItem = ps.GetStringSplitPOCO();
            return View(rm);
        }

and here is the view.Three getting data from Web Api and one using Binding directly to Typed View POCO.


@model Hotel.Web.Models.RegisterModel
@{
    ViewBag.Title = "Home Page";
}

<div class="demo-section" style="width: 250px;">
    <h2>Items</h2>
    @(Html.Kendo().DropDownList()
          .Name("ApiItems")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("Item")
          .DataValueField("SN")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Url("http://localhost:1483/api/Default/GetStringSplit");
              });
          })
    )
</div>

<div class="demo-section" style="width: 250px;">
    <h2>Items</h2>
    @(Html.Kendo().DropDownList()
          .Name("ApiItemsPOCO")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("Item")
          .DataValueField("SN")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Url("http://localhost:1483/api/Default/GetStringSplitPOCO");
              });
          })
    )
</div>

<div class="demo-section" style="width: 250px;">
    <h2>Items</h2>
    @(Html.Kendo().DropDownList()
          .Name("ModelItemPOCO")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("Item")
          .DataValueField("SN")
          .BindTo(Model.NewTestItem)
    )
</div>

<div class="demo-section" style="width: 250px;">
    <h2>RoomType</h2>
    @(Html.Kendo().DropDownList()
          .Name("ApiRoomType")
          .HtmlAttributes(new { style = "width: 250px" })
          .DataTextField("RoomType")
          .DataValueField("RoomTypeId")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Url("http://localhost:1483/api/Default/GetRoomType");
              });
          })
    )
</div>



        public IQueryable<TfStringSplitResult1Row> GetStringSplitPOCO()
        {
            IQueryable<TfStringSplitResult1Row> q;
            DataAccessAdapter adapter = new DataAccessAdapter();
                var metaData = new LinqMetaData(adapter);
                q = from c in metaData.TfStringSplit1("a,b,c,d,", ",")
                    select c;
            return q;
        }

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Mar-2015 18:50:08   

Did you try the second link I've shared (using a ViewModel object)?

hotmail
User
Posts: 47
Joined: 06-Feb-2013
# Posted on: 26-Mar-2015 17:12:20   

Yes, ViewModel worked Thanks

larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 16-Apr-2015 22:04:46   

Hi, I thought I'd piggy-back on this conversation. I too received the circular reference message and tried following Franz Bouma's instructions at http://weblogs.asp.net/fbouma/how-to-make-asp-net-webapi-serialize-your-llblgen-pro-entities-to-json. Now, when I go to rebuild my llblgen classes, I get an error for each entity that goes something like this:

The type or namespace name 'DataContractAttribute' could not be found (are you missing a using directive or an assembly reference?)

I double and triple-checked that I set my settings correctly and they seem correct. I'm using LLBLGen Pro Runtime Framework, Self-servicing, two classes, if that makes a difference. Or do I need to add a reference to my LLBLGen project? The errors point to the [DataContract] attribute towards the top of each entity base class.

    [Serializable]
    [DataContract]
    public abstract partial class CategoryLookupEntityBase : CommonEntityBase
        // __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
        // __LLBLGENPRO_USER_CODE_REGION_END    

Any ideas?

Many thanks!

Laurie

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Apr-2015 09:13:51   

[DataContract] and [DataMember] attribute are found in System.ServiceModel namespace which is in System.ServiceModel.dll .

System.ServiceModel uses the System and System.Runtime.Serialization namespaces to serialize the datamembers.

So, make sure that you added the necessary assemblies references.

David Elizondo | LLBLGen Support Team
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 22-Apr-2015 18:26:17   

We have achieved build. Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Apr-2015 07:59:08   

Good to know you made it sunglasses Thanks for the feedback.

David Elizondo | LLBLGen Support Team