ObjectDisposedException (IServiceProvider) after DataPortalException in SaveAsync with AutoCloneOnUpdate=false
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
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 This seems to fix it (tried with the linked example and a more complex WPF app).
@rockfordlhotka We should fix that
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.
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.