ListView Mvc Helper throws exception when model contains DbGeometry object

7 posts, 0 answers
  1. Jeff
    Jeff avatar
    14 posts
    Member since:
    May 2013

    Posted 13 Jun 2013 Link to this post

    Hi,

    I currently have a model with several properties, one of which is a Spatial object (of type DbGeometry). If this spatial property is NULL, everything works fine, but if it's not, my ListView throws an exception (ironically enough, it thinks the problem is that the list is null). My list creation code is below:

    @(Html.Kendo().ListView(Model.ToList())
        .Name("s-list-event-container")
        .TagName("div")
        .HtmlAttributes(new { @class = "s-list-container" })
        .ClientTemplateId("template-list-event")
    )
    where "Model" refers to an IEnumerable object.

    If there is no way to populate the ListView while the model has a DbGeometry object, is there at least a way to ignore specific properties of a model?

    Thanks,
    Jeff
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 17 Jun 2013 Link to this post

    Hello Jeff,

    Whats the exception that is thrown when the objects is different than null? Is it a serialization error? I assume it is circular reference serialization error.

    If yes I would suggest you to follow the suggestion and use 'View Model'. If not could you share details about the error?

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Jeff
    Jeff avatar
    14 posts
    Member since:
    May 2013

    Posted 17 Jun 2013 Link to this post

    The error is a "Data is NULL" error thrown by a validator. I'll post the full error at a later time, but at the moment I cannot alter the code in a way that would break it.

    I have no circular references in my model (I know I don't because I used to).
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 19 Jun 2013 Link to this post

    Hello Jeff,

    What is that validator? Could you please let us know how we can reproduce the case that you experience so we can search for a resolution?

    Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Jeff
    Jeff avatar
    14 posts
    Member since:
    May 2013

    Posted 19 Jun 2013 Link to this post

    I have not tried this myself, but I believe you should be able to reproduce this error by creating a new MVC project using a database table with at least one field of type [sys].[geometry] (DbGeometry in ASP.NET), and attempting to wire up the model for said table to a ListView. If this does not produce the error, let me know and I'll produce some of my model/table data.

    Here is the error:
    Data is Null. This method or property cannot be called on Null values.
    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.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
    And a portion of the stack trace:
    01.[SqlNullValueException: Data is Null. This method or property cannot be called on Null values.]
    02.System.Data.SqlTypes.SqlDouble.get_Value() +1929545
    03. 
    04.[TargetInvocationException: Exception has been thrown by the target of an invocation.]
    05.System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
    06.System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
    07.System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +108
    08.System.Web.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args) +148
    09.System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +782
    10.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
    11.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
    12.System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +820
    13.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
    14.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
    15.System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +820
    16.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
    17.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
    18.System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +820
    19.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2834
    20.System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371
    21.System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +57
    22.System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +83
    23.System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +44
    Thanks,
    Jeff
  7. Jeff
    Jeff avatar
    14 posts
    Member since:
    May 2013

    Posted 19 Jun 2013 Link to this post

    I have not tried this myself, but I believe you should be able to reproduce this error by creating a new MVC project using a database table with at least one field of type [sys].[geometry] (DbGeometry in ASP.NET), and attempting to wire up the model for said table to a ListView. If this does not produce the error, let me know and I'll produce some of my model/table data.

    Here is the error:
    Data is Null. This method or property cannot be called on Null values.
    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.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
    And a portion of the stack trace:
    01.[SqlNullValueException: Data is Null. This method or property cannot be called on Null values.]
    02.System.Data.SqlTypes.SqlDouble.get_Value() +1929545
    03. 
    04.[TargetInvocationException: Exception has been thrown by the target of an invocation.]
    05.System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
    06.System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
    07.System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +108
    08.System.Web.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args) +148
    09.System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +782
    Thanks,
    Jeff
  8. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 21 Jun 2013 Link to this post

    Hello Jeff,

    Thank you for providing details about the exception.

    I assume (I have helped on similar issue) that the problem is arising because  of that field  which could not be serialized.
    Do you need to bind a column to it?
    If not you can ignore that field from serialization like this:

    [ScriptIgnore()]
    public System.Data.Spatial.DbGeometry Geom { get; set; }

    by adding the ScriptIgnore attribute.

    If you need any information from this field (you do not want to ignore it) you can create ViewModel and project only the fields which you need and so it can be successfully serialized.

    I hope this helps.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready