csla icon indicating copy to clipboard operation
csla copied to clipboard

ObjectDisposedException (IServiceProvider) after DataPortalException in SaveAsync with AutoCloneOnUpdate=false

Open ka-fim opened this issue 1 year ago • 3 comments

Describe the bug Can't access any managed property of a business object (throwing ObjectDisposedException) after trying to save it and an exception occured in a DataPortal method

Version and Platform CSLA version: 8.2.7 OS: Windows (probably independent but not tested) Platform: Console App, WPF (probably independent but not tested)

Code that Fails https://github.com/ka-fim/CslaIServiceProviderDisposedException

Stack Trace or Exception Detail System.ObjectDisposedException HResult=0x80131622 Message=Cannot access a disposed object. Object name: 'IServiceProvider'. Source=Microsoft.Extensions.DependencyInjection StackTrace: at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException() at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Csla.Core.ApplicationContextAccessor.GetContextManager() at Csla.ApplicationContext.get_ContextManager() at Csla.ApplicationContext.get_User() at Csla.Core.BusinessBase.VerifyAuthorizationCache() at Csla.Core.BusinessBase.CanWriteProperty(IPropertyInfo property) at Csla.Core.BusinessBase.CanWriteProperty(IPropertyInfo property, Boolean throwOnFalse) at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo1 propertyInfo, P newValue, NoAccessBehavior noAccess) at Csla.Core.BusinessBase.SetProperty[P](PropertyInfo1 propertyInfo, P newValue) at CslaIServiceProviderDisposedException.DataPortalExceptionBusinessObject.set_Name(String value) in C:\TestProjects\CslaIServiceProviderDisposedException\DataPortalExceptionBusinessObject.cs:line 13 at Program.<<Main>$>d__0.MoveNext() in C:\TestProjects\CslaIServiceProviderDisposedException\Program.cs:line 31

Additional context Setting up the DataPortal with UseLocalProxy and AutoCloneOnUpdate = false

ka-fim avatar Sep 18 '24 10:09 ka-fim

Please try and configure .UseLocalProxy(lp => lp.UseLocalScope = false). Does the error persist with this setting? I suspect the returned object from save is still "bound" to the local scope created during save. But the scope is disposed after the save operation.

ossendorf-at-hoelscher avatar Sep 18 '24 11:09 ossendorf-at-hoelscher

@ossendorf-at-hoelscher This seems to fix it (tried with the linked example and a more complex WPF app).

ka-fim avatar Sep 18 '24 12:09 ka-fim

@rockfordlhotka We should fix that

ossendorf-at-hoelscher avatar Sep 18 '24 12:09 ossendorf-at-hoelscher

The fix I've implemented does not require the workaround mentioned earlier in this thread, and makes the data portal work as expected with autoclone on update disabled.

rockfordlhotka avatar Nov 04 '24 20:11 rockfordlhotka

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar May 04 '25 00:05 github-actions[bot]