MarimerLLC / csla

A home for your business logic in any .NET application.
https://cslanet.com
MIT License
1.27k stars 406 forks source link

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

Closed ka-fim closed 3 weeks ago

ka-fim commented 2 months ago

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.<

$>d__0.MoveNext() in C:\TestProjects\CslaIServiceProviderDisposedException\Program.cs:line 31

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

ossendorf-at-hoelscher commented 2 months ago

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.

ka-fim commented 2 months ago

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

ossendorf-at-hoelscher commented 2 months ago

@rockfordlhotka We should fix that

rockfordlhotka commented 3 weeks ago

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.