- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Kendo Grid Server Wrapper with LLBLGen Entity Exception
Joined: 06-Feb-2013
using llblgen 4.2 latest with sql server 2014. asp.net MVC, asp.net Web Api and Kendo UI grid.
when i set the entity to Kendo UI Grid. i get the following exception.
can i get some help how to resolve it? Thanks
Here is the code.
<div>
@(Html.Kendo().Grid<Mars.EntityClasses.VwPersonEntity>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.GenderName);
columns.Bound(p => p.RoleName);
columns.Command(c =>
{
c.Edit();
c.Destroy();
});
})
.ToolBar(tools =>
{
tools.Create();
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Sortable()
.Pageable()
.Filterable()
.DataSource(d => d
.Ajax()
.Model(model =>
{
model.Id(p => p.PersonId);
})
.Read(read => read.Url("http://localhost:24667/api/HumanResource/PersonEntityCollection").Type(HttpVerbs.Get))
.Create(create => create.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Post))
.Update(update => update.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Delete))
)
)
</div>
here is the exception
Server Error in '/' Application.
Fields can't be set to null
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: Fields can't be set to null
Source Error:
Line 7:
Line 8: <div>
Line 9: @(Html.Kendo().Grid<Mars.EntityClasses.VwPersonEntity>()
Line 10: .Name("Grid")
Line 11: .Columns(columns =>
Source File: c:\Users\hotmail\Documents\Visual Studio 2013\Projects\Mars\Mars.Web\Areas\HumanResource\Views\Home\Index.cshtml Line: 9
Stack Trace:
[InvalidOperationException: Fields can't be set to null]
SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.set_Fields(TFields value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.2\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityCore.cs:4059
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +155
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +97
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +22
Kendo.Mvc.UI.<>c__DisplayClass2.<CreateDefaultItem>b__0(ModelFieldDescriptor f) +327
Kendo.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +194
Kendo.Mvc.UI.GridEditableSettings`1.CreateDefaultItem() +1064
Kendo.Mvc.UI.Grid`1.InitializeEditors() +609
Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +1059
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_Areas_HumanResource_Views_Home_Index_cshtml.Execute() in c:\Users\hotmail\Documents\Visual Studio 2013\Projects\Mars\Mars.Web\Areas\HumanResource\Views\Home\Index.cshtml:9
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +122
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
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209
The grid apparently wants to use reflection to set values on the entity type, which is odd. But I don't know what the grid does or why it does it that way. The grid shouldn't set values based on reflection. It reflects over the properties of the entity, and sets everything to null it seems, which raises an exception as some properties aren't to be set to null.
If you bind an entity collection to it it should work though, as that implements IListSource and ITypedList. If the grid can't deal with that, you have to consult with Telerik how they think it should be solved. In the worst case scenario you have to define the columns manually so the grid won't try to determine them automatically (which goes wrong in some grids, as the grid developers in general simply reflect over the type and use all properties found, ignoring other systems like ITypedList)
Joined: 06-Feb-2013
when i use entity collection and define the columns manually i get other exception.
here is the code with entity collection
<div>
@(Html.Kendo().Grid<Mars.HelperClasses.EntityCollection<Mars.EntityClasses.VwPersonEntity>>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound("Name");
columns.Bound("GenderName");
columns.Bound("RoleName");
columns.Command(c =>
{
c.Edit();
c.Destroy();
});
})
.ToolBar(tools =>
{
tools.Create();
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Sortable()
.Pageable()
.Filterable()
.DataSource(d => d
.Ajax()
.Model(model =>
{
model.Id("PersonId");
})
.Read(read => read.Url("http://localhost:24667/api/HumanResource/PersonEntityCollection").Type(HttpVerbs.Get))
.Create(create => create.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Post))
.Update(update => update.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url("http://localhost:24667/api/HumanResource/PersonEntity").Type(HttpVerbs.Delete))
)
)
</div>
here is the exception
Server Error in '/' Application.
Invalid property or field - 'Name' for type: EntityCollection`1
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.ArgumentException: Invalid property or field - 'Name' for type: EntityCollection`1
Source Error:
Line 39: .Columns(columns =>
Line 40: {
Line 41: columns.Bound("Name");
Line 42: columns.Bound("GenderName");
Line 43: columns.Bound("RoleName");
Source File: c:\Users\hotmail\Documents\Visual Studio 2013\Projects\Mars\Mars.Web\Areas\HumanResource\Views\Home\Index.cshtml Line: 41
Stack Trace:
[ArgumentException: Invalid property or field - 'Name' for type: EntityCollection`1]
Kendo.Mvc.Infrastructure.Implementation.Expressions.MemberAccessTokenExtensions.CreateMemberAccessExpression(IMemberAccessToken token, Expression instance) +185
Kendo.Mvc.Infrastructure.Implementation.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName) +116
Kendo.Mvc.Infrastructure.Implementation.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Boolean liftMemberAccessToNull) +50
Kendo.Mvc.Infrastructure.Implementation.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpression() +155
Kendo.Mvc.Infrastructure.Implementation.Expressions.MemberAccessExpressionBuilderBase.CreateLambdaExpression() +61
Kendo.Mvc.ExpressionBuilder.Lambda(Type memberType, String memberName, Boolean checkForNull) +146
Kendo.Mvc.UI.Fluent.GridColumnFactory`1.Bound(Type memberType, String memberName) +163
Kendo.Mvc.UI.Fluent.GridColumnFactory`1.Bound(String memberName) +46
ASP._Page_Areas_HumanResource_Views_Home_Index_cshtml.<Execute>b__3(GridColumnFactory`1 columns) in c:\Users\hotmail\Documents\Visual Studio 2013\Projects\Mars\Mars.Web\Areas\HumanResource\Views\Home\Index.cshtml:41
Kendo.Mvc.UI.Fluent.GridBuilder`1.Columns(Action`1 configurator) +202
ASP._Page_Areas_HumanResource_Views_Home_Index_cshtml.Execute() in c:\Users\hotmail\Documents\Visual Studio 2013\Projects\Mars\Mars.Web\Areas\HumanResource\Views\Home\Index.cshtml:18
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +122
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
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209
What does Telerik say? It's a crash in their code after all. They apparently can't handle objects which implement ITypedList, IListSource...
I hate to kick the ball into another one's court, but I have no idea what to do about this as it's a crash outside our code using the classes we generate, and ignoring the interfaces we implemented to help grids like this one to obtain column information etc.
E.g. if you bind a datatable to the grid, it can obtain the grid columns automatically I recon, which uses the exact same interfaces as our code does.