Bug Report T335703
Visible to All Users

The View.SelectedObjects property returns a collection of disposed objects in certain circumstances

created 9 years ago (modified 9 years ago)

In the meantime, you can use the following workaround:

C#
public class MyController : ViewController<ListView> { protected override void OnActivated() { base.OnActivated(); ObjectSpace.Reloaded += ObjectSpace_Reloaded; } void ObjectSpace_Reloaded(object sender, EventArgs e) { FieldInfo fi = typeof(DevExpress.ExpressApp.Web.Editors.ComplexWebListEditor).GetField("isSelectedObjectsCacheActual", BindingFlags.Instance | BindingFlags.NonPublic); if(fi != null) { fi.SetValue(View.Editor, false); } } }

See the attached projects for more details.
- Solution61:

C#
public class TestSelectedObjectsController : ViewController<ListView> { protected override void OnActivated() { base.OnActivated(); View.Editor.ControlsCreated += Editor_ControlsCreated; } void Editor_ControlsCreated(object sender, EventArgs e) { ((ASPxGridView)View.Editor.Control).HtmlRowPrepared += TestSelectedObjectsController_HtmlRowPrepared; } void TestSelectedObjectsController_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e) { if(View.SelectedObjects.Count > 0) { Session session = ((Object1)View.SelectedObjects[0]).Session; <- error occurred } } }

- Solution72:

C#
[DefaultClassOptions] public class Class1 : BaseObject { public Class1(Session session) : base(session) { } public string Name { get { if(IsSaving) { <- error occurred return GetPropertyValue<string>("Name"); } return GetPropertyValue<string>("Name"); } set { SetPropertyValue<string>("Name", value); } } } public class MyController : ViewController { public MyController() { SimpleAction action = new SimpleAction(this, "Print", PredefinedCategory.Export); action.SelectionDependencyType = SelectionDependencyType.RequireSingleObject; action.ConfirmationMessage = "Are you sure?"; } } The error occurred:  Type:       ObjectDisposedException  Message:    Cannot access a disposed object. Object name: 'Solution72.Module.BusinessObjects.Class1(3899f9f8-3443-4f0f-9151-0b553f6d4aff)'.  Data:       0 entries  Stack trace:    at DevExpress.Xpo.PersistentBase.get_Session()    at DevExpress.Xpo.PersistentBase.get_IsSaving()    at Solution72.Module.BusinessObjects.Class1.get_Name() in c:\Projects\Solution72\Solution72.Module\BusinessObjects\Class1.cs:line 18    at lambda_method(Closure , Object )    at DevExpress.Xpo.Metadata.ReflectionMemberInfo.DelegateFieldAccessor.GetValue(Object theObject)    at DevExpress.Xpo.Metadata.ReflectionMemberInfo.GetValue(Object theObject)    at DevExpress.ExpressApp.DC.Xpo.XpoTypeInfoSource.GetValue(IMemberInfo memberInfo, Object obj)    at DevExpress.ExpressApp.DC.XafMemberInfo.GetValue(Object obj)    at DevExpress.Persistent.Base.ReflectionHelper.GetObjectDisplayText(Object obj)    at DevExpress.ExpressApp.Actions.ActionBase.GetFormattedConfirmationMessage()    at DevExpress.ExpressApp.Templates.ActionBaseItem.SynchronizeWithActionCore()    at DevExpress.ExpressApp.Web.Templates.ActionContainers.Menu.MenuActionItemBase..ctor(ActionBase action)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.CreateSimpleActionItem(SimpleAction simpleAction)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.CreateActionItem(ActionBase action)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.AddActionItem(MenuItemCollection targetItemCollection, ActionBase action, Boolean isFirstItem)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.RegisterContainerActions(WebActionContainer container)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.CreateMenuItems()    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.CreateChildControls()    at System.Web.UI.Control.EnsureChildControls()    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.ExecuteMenuItem(IList`1 items, String indexPath)    at DevExpress.ExpressApp.Web.Templates.ActionContainers.ActionContainerHolder.DevExpress.ExpressApp.Web.Templates.IXafCallbackHandler.ProcessAction(String parameter)    at DevExpress.ExpressApp.Web.Templates.XafCallbackManager.ProcessAction(String parameter)    at DevExpress.ExpressApp.Web.Templates.XafCallbackManager.callbackControl_Callback(Object source, CallbackEventArgs e)    at DevExpress.Web.ASPxCallback.OnCallback(CallbackEventArgs e)    at DevExpress.Web.ASPxCallback.RaiseCallbackEvent(String eventArgument)    at DevExpress.Web.ASPxWebControl.System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)  InnerException is null

Answers approved by DevExpress Support

created 9 years ago

We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

    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.