MarimerLLC / csla

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

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

Open ka-fim opened 1 week ago

ka-fim commented 1 week 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 1 week 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 1 week ago

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

ossendorf-at-hoelscher commented 1 week ago

@rockfordlhotka We should fix that