NullReferenceException in SfDataGrid when using Castle DynamicProxy objects as ItemsSource

when double clicking to create a new row, an exception gets raised:

an unhandled exception of type 'System.NullReferenceException' occurred in DynamicProxyGenAssembly2

am using SfDataGrid with ItemsSource bound to a tracked collection of type Castle.Proxies.ItemProxy which is generated by this widely used ChangeTracking library which is based on Castle DynamicProxy

the weird thing is, the problem doesn't happen when i use the default WPF DataGrid control, it only happens when i use the SfDataGrid control?

So is there any way to solve this? How can i use SfDataGrid along with Proxy objects?


Attachment: WpfApp1_fd2415ca.zip


9 Replies

SS Sampathnarayanan Sankaralingam Syncfusion Team February 17, 2022 02:12 PM UTC

Hi Joseph, 

We are able to replicate the reported issue with your provided sample. We will validate and update you with more details on February 21, 2022. 

Regards, 
Sampath Narayanan.S 



SS Sampathnarayanan Sankaralingam Syncfusion Team February 21, 2022 11:50 AM UTC

Hi Joseph,  

We are still validating the issue. We will validate and update you with more details on February 23, 2022. 

Regards, 
Sampath Narayanan.S 



SS Sampathnarayanan Sankaralingam Syncfusion Team February 23, 2022 02:18 PM UTC

Hi Joseph,   

You are using the ChangeTracking Library which changed the items to type Castle.Proxies.ItemProxy and the ItemSource is bound to the tracked collection of type Castle.Proxies.ItemProxy. We have checked in our source and we didn’t have  support to such type trackable collection. However, you can fix the issue while adding new row by setting the AddNewRowInitiatingEventArgs.NewObject as underlying object type in SfDataGrid.AddNewRowInitiating as shown in the below code changes.  


private void SfDataGrid_AddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs e) 
{ 
    e.NewObject = new Item() { Name = " " }; 
} 



Regards, 
Sampath Narayanan.S  



JO Joseph February 23, 2022 10:50 PM UTC

thanks for your reply!

but now if you try and edit any newly added row field you get an exception:

An unhandled exception of type 'System.InvalidCastException' occurred in System.Private.CoreLib.dll

Unable to cast object of type 'WpfApp1.Item' to type 'Castle.Proxies.ItemProxy'.



MA Mohanram Anbukkarasu Syncfusion Team February 24, 2022 02:01 PM UTC

Hi Joseph, 

We have checked the reported scenario in our end and we could edit the newly added row without any exception. We have attached a video illustration in the following link for your reference.  


Please have a look at this and revert to us with more details and video illustration of the issue if we have misunderstood your scenario.  

Regards, 
Mohanram A. 



JO Joseph February 24, 2022 10:10 PM UTC

am sorry to inform you but the exception does clearly happen when you edit a new row field and just to be precise, it happens exactly at the moment you finish editing a field THEN click away to another row using the mouse?

if you press tab when you finish the exception doesn't happen???



SS Sampathnarayanan Sankaralingam Syncfusion Team February 25, 2022 07:49 PM UTC

Hi Joseph, 


We are checking the reported issue. We will update you with more details on March 1, 2022.


Regards,

Sampath Narayanan.S



JO Joseph February 27, 2022 02:43 PM UTC

OK it seems the problem gets actually fixed by setting the SfDataGrid.SourceType just like you said.

am sorry for the inconvenience, I just wasn't paying attention enough!

you saved the day, Big Thanks To YOU!



SS Sampathnarayanan Sankaralingam Syncfusion Team February 28, 2022 09:51 PM UTC

Hi Joseph,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.


Regards,

Sampath Narayanan.S


Loader.
Up arrow icon