Unable to cast object XXX to ExpandoObject when using a class that inherits from base class inheriting from DynamicObject
Hello,
My application uses the grid component to display data with a variable number of columns.
To do this, I use a class that inherits from DynamicObject, as explained in the documentation. Everything works correctly when my class inherits directly from DynamicObject.
There are, however, several different grids to display. To optimize the management of variable columns, I inherited two classes from a base class which itself inherits from DynmaicObject:
But if I use one of these classes, the grid stops working and the following error appears during validation after editing:
Unable to cast object 'TeamCashbox.Models.AccountingDocument' to type 'Sytsem.Dynamic.ExpandoObject'
Here is a screenshot of the exception:
Do you think it is possible to use a child class of DynamicObject in the grid control?
Hi Gasser,
Greetings from Syncfusion.
Before proceeding further with your requirement kindly share us the below details to validate further at our end.
- Share us the entire Grid code snippet.
- Share us the video demonstration of the reported issue.
- the following error appears during validation after editing -> share us the way you have handled validation at your end.
- Share us the Nuget version used at your end.
- If possible share us an simple issue replicating sample.
The above requested details will be very helpful for us to validate the reported issue at our end.
Regards,
Monisha
Hello Monisha,
Please find a sample project below.
To reproduce the error:
- Choose “Test grid” in the left menu
- Double-click on a line to edit it
- Then click on the “Update” button in the grid toolbar
- This action should invoke the "OnGridActionFailure" function on which I have defined a breakpoint
Thank you in advance for your help
Regards,
J-D Gasser
Attachment: UnableToCastObjectToExpandoObject_24ba4608.zip
Hi Jean,
From your query, we were able to replicate the reported issue on our end. After
examining your shared sample, we noticed that you're accessing properties of
dynamic objects and binding them to strongly typed objects. This is causing
some issues during data operations. To address this problem, we recommend using
Dynamic or ExpandoObject, which we have provided built-in support for perform
CRUD operation, or alternatively, use fully strongly typed objects in the Grid
to overcome the reported issue at your end. Please refer to the attached link
for more information.
Reference: https://blazor.syncfusion.com/documentation/datagrid/data-binding#dynamicobject-binding
Demo: https://blazor.syncfusion.com/demos/datagrid/dynamicobject?theme=fluent
If you have any further queries, please get back to us.
Regards,
Sarvesh
- 3 Replies
- 4 Participants
-
GA Gasser
- Mar 12, 2024 07:28 AM UTC
- Mar 18, 2024 02:47 PM UTC