Ticket T123238
Visible to All Users

InvalidCastException (permissionRequest.TargetObject incompatible with targetObject.GetType()) occurs with a custom banded list editor

created 11 years ago

In our own list editor, we get the following exception when the selection is changed, when calling the base method OnSelectionChanged of the ListEditor:

bei DevExpress.ExpressApp.Security.ServerPermissionRequestProcessor.GetTypeToProcess(Type targetType, Object targetObject)
   bei DevExpress.ExpressApp.Security.ServerPermissionRequestProcessor.IsGrantedCore(ServerPermissionRequest permissionRequest, IPermissionDictionary permissions, Boolean needToCheckBackReference)
   bei DevExpress.ExpressApp.Security.ServerPermissionRequestProcessor.DevExpress.ExpressApp.Security.IPermissionRequestProcessor.IsGranted(IPermissionRequest permissionRequest)
   bei DevExpress.ExpressApp.Security.ClientPermissionRequestProcessor.IsGranted(ClientPermissionRequest clientPermissionRequest)
   bei DevExpress.ExpressApp.Security.ClientPermissionRequestProcessor.DevExpress.ExpressApp.Security.IPermissionRequestProcessor.IsGranted(IPermissionRequest permissionRequest)
   bei DevExpress.ExpressApp.Security.SelectDataSecurity.IsGranted(IPermissionRequest permissionRequest)
   bei DevExpress.ExpressApp.Security.SecurityStrategy.IsGranted(IPermissionRequest permissionRequest)
   bei DevExpress.ExpressApp.DataManipulationRight.IsPermissionGranted(IPermissionRequest permissionRequest)
   bei DevExpress.ExpressApp.DataManipulationRight.HasPermissionTo(Type objectType, String memberName, Object targetObject, IObjectSpace objectSpace, String operation)
   bei DevExpress.ExpressApp.DataManipulationRight.CanDelete(Type type, Object targetObject, CollectionSourceBase collectionSourceBase, IObjectSpace objectSpace)
   bei DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController.UpdateActionState()
   bei DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController.DoUpdateActionState()
   bei DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController.View_SelectionChanged(Object sender, EventArgs e)
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei DevExpress.ExpressApp.View.OnSelectionChanged()
   bei DevExpress.ExpressApp.ListView.listEditor_SelectionChanged(Object sender, EventArgs e)
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei DevExpress.ExpressApp.Editors.ListEditor.OnSelectionChanged()
   bei BaseUserControlCommon.BandedListEditor.OnSelectionChanged() in c:\dev\Tools\Lvs\trunk\LvsHelper\BaseUserControlCommon\BandedListEditor.cs:Zeile 325.

Exception source: DevExpress.ExpressApp.Security.v13.2

How can we prevent that error?

Martin

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello Martin,

It appears that an object of a type that is not inherited from the ListView's object type is returned by the GetSelectedObjects method of your list editor. For example, this may occur if you implemented the master-detail functionality. In this case, the GetSelectedObjects method should not return records selected in detail grids. It should return only records from the main (root) grid. Alternatively, you can override the DeleteObjectsViewController.UpdateActionState method to support selecting records whose type is not inherited from the View's object type. However, I cannot guarantee that other controllers will work correctly in this situation.

    Comments (1)

      Hi Anatol,
      indeed we have developed our own banded list editor and since the 13.2.9 release the DeleteObjectsViewController throws the mentioned InvalidCastException "permissionRequest.TargetObject incompatible with targetObject.GetType()". It is not clear to me why it was working in the previous version, but with your recommendation with inheriting the DeleteObjectsViewController it works so far.
      Thanks.
      Martin

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.