edandersen / core-admin

Fully automatic admin site CRUD UI generator for ASP.NET Core and .NET 8
Other
599 stars 111 forks source link

DateTimeOffset causes exception #66

Closed tombohub closed 2 years ago

tombohub commented 2 years ago

I have followed installation for .NET 6.

this is the model I have:

public class Movie
    {
        public int Id { get; set; }
        public string? Title { get; set; }

        [DataType(DataType.Date)]
        public DateTime ReleaseDate { get; set; }
        public string? Genre { get; set; }
        public decimal Price { get; set; }
    }

and when trying to view this model in coreadmin there's an error:

ArgumentException: Expression of type 'System.Decimal' cannot be used for return type 'System.Object'

Full stack trace:

System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, ref Expression body, ReadOnlyCollection<ParameterExpression> parameters, string paramName)
System.Linq.Expressions.Expression.Lambda<TDelegate>(Expression body, string name, bool tailCall, IEnumerable<ParameterExpression> parameters)
AspNetCoreGeneratedDocument.Views_CoreAdminData_Index+<>c__DisplayClass0_0.<ExecuteAsync>b__0(IGridColumnsOf<object> columns)
NonFactors.Mvc.Grid.HtmlGridExtensions.Build<T>(IHtmlGrid<T> html, Action<IGridColumnsOf<T>> builder)
AspNetCoreGeneratedDocument.Views_CoreAdminData_Index.ExecuteAsync()
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Thank you

danroot commented 2 years ago

I'm seeing similar - some entities work, some fail with an error similar to above.

Expression of type 'System.Nullable`1[System.Decimal]' cannot be used for return type 'System.Object'
Expression of type 'System.Nullable`1[System.DateTime]' cannot be used for return type 'System.Object'
Expression of type 'System.Nullable`1[System.Int32]' cannot be used for return type 'System.Object'
Expression of type 'System.DateTime' cannot be used for return type 'System.Object'

As best I can tell, line 28 -99 in https://github.com/edandersen/core-admin/blob/master/src/DotNetEd.CoreAdmin/Views/CoreAdminData/Index.cshtml are the issue, but not quite following the code enough to do a PR.

edandersen commented 2 years ago

Fixed in 2.6.0 :-)

kedare commented 2 years ago

I still have the same issue with 2.6.0 (on a blank new asp.net project, when going to the user model /CoreAdminData/Index/Users)

edandersen commented 2 years ago

What's the error on this new entity?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Mathieu Poussin @.> Sent: Saturday, May 14, 2022 5:15:12 PM To: edandersen/core-admin @.> Cc: Ed Andersen @.>; State change @.> Subject: Re: [edandersen/core-admin] ArgumentException: Expression of type 'System.Decimal' cannot be used for return type 'System.Object' (Issue #66)

I still have the same issue with 2.6.0 (on a blank new asp.net project, when going to the user model /CoreAdminData/Index/Users)

— Reply to this email directly, view it on GitHubhttps://github.com/edandersen/core-admin/issues/66#issuecomment-1126762663, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEF6HHBGCM4JRJHDIPHTETVJ7GRBANCNFSM5U2OTQWA. You are receiving this because you modified the open/close state.Message ID: @.***>

kedare commented 2 years ago
System.ArgumentException: Expression of type 'System.Nullable`1[System.DateTimeOffset]' cannot be used for return type 'System.Object'
   at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection`1 parameters, String paramName)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
   at AspNetCoreGeneratedDocument.Views_CoreAdminData_Index.<>c__DisplayClass0_0.<ExecuteAsync>b__0(IGridColumnsOf`1 columns)
   at NonFactors.Mvc.Grid.HtmlGridExtensions.Build[T](IHtmlGrid`1 html, Action`1 builder)
   at AspNetCoreGeneratedDocument.Views_CoreAdminData_Index.ExecuteAsync()
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Indeed sorry it's not exactly the same error but quite similar

edandersen commented 2 years ago

Looks like datetime offset needs support too. Will get on it. Thanks.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Mathieu Poussin @.> Sent: Saturday, May 14, 2022 5:38:07 PM To: edandersen/core-admin @.> Cc: Ed Andersen @.>; State change @.> Subject: Re: [edandersen/core-admin] ArgumentException: Expression of type 'System.Decimal' cannot be used for return type 'System.Object' (Issue #66)

System.ArgumentException: Expression of type 'System.Nullable1[System.DateTimeOffset]' cannot be used for return type 'System.Object' at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection1 parameters, String paramName) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable1 parameters) at AspNetCoreGeneratedDocument.Views_CoreAdminData_Index.<>c__DisplayClass0_0.<ExecuteAsync>b__0(IGridColumnsOf1 columns) at NonFactors.Mvc.Grid.HtmlGridExtensions.Build[T](IHtmlGrid1 html, Action1 builder) at AspNetCoreGeneratedDocument.Views_CoreAdminData_Index.ExecuteAsync() at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context) at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts) at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

— Reply to this email directly, view it on GitHubhttps://github.com/edandersen/core-admin/issues/66#issuecomment-1126772475, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEF6HD3743NMDRQA3XY3JDVJ7JG7ANCNFSM5U2OTQWA. You are receiving this because you modified the open/close state.Message ID: @.***>

kedare commented 2 years ago

Should I open a new issue for that ?

edandersen commented 2 years ago

No, I will pick it up, reopened.

edandersen commented 2 years ago

Okay DateTimeOffset should be supported in 2.6.1. Thanks!

danroot commented 2 years ago

There were still some types missing for my db- nullables and int64. I created a pull request with them: https://github.com/edandersen/core-admin/pull/69