diff --git a/NuGet/Definition/Csla.AspNetCore.NuSpec b/NuGet/Definition/Csla.AspNetCore.NuSpec index 6439a9f722..fede6afdff 100644 --- a/NuGet/Definition/Csla.AspNetCore.NuSpec +++ b/NuGet/Definition/Csla.AspNetCore.NuSpec @@ -32,8 +32,8 @@ - - + + diff --git a/NuGet/Definition/Csla.Blazor.NuSpec b/NuGet/Definition/Csla.Blazor.NuSpec index f31aeffc11..1461ab3cce 100644 --- a/NuGet/Definition/Csla.Blazor.NuSpec +++ b/NuGet/Definition/Csla.Blazor.NuSpec @@ -36,9 +36,9 @@ - - - + + + diff --git a/NuGet/Definition/Csla.Blazor.WebAssembly.NuSpec b/NuGet/Definition/Csla.Blazor.WebAssembly.NuSpec index 49b5bde758..fa496ac36f 100644 --- a/NuGet/Definition/Csla.Blazor.WebAssembly.NuSpec +++ b/NuGet/Definition/Csla.Blazor.WebAssembly.NuSpec @@ -35,7 +35,7 @@ - + diff --git a/NuGet/Definition/Csla.NuSpec b/NuGet/Definition/Csla.NuSpec index 4e070dd2cd..aa5928f595 100644 --- a/NuGet/Definition/Csla.NuSpec +++ b/NuGet/Definition/Csla.NuSpec @@ -92,12 +92,12 @@ - - - - - - + + + + + + diff --git a/NuGet/Definition/Csla.Windows.Forms.NuSpec b/NuGet/Definition/Csla.Windows.Forms.NuSpec index 945508a002..9e2553aa14 100644 --- a/NuGet/Definition/Csla.Windows.Forms.NuSpec +++ b/NuGet/Definition/Csla.Windows.Forms.NuSpec @@ -33,8 +33,8 @@ - - + + diff --git a/NuGet/Definition/Csla.Wpf.NuSpec b/NuGet/Definition/Csla.Wpf.NuSpec index 23d10f12bb..a12920ddfc 100644 --- a/NuGet/Definition/Csla.Wpf.NuSpec +++ b/NuGet/Definition/Csla.Wpf.NuSpec @@ -34,7 +34,7 @@ - + diff --git a/Source/Csla.Analyzers/Csla.Analyzers.Tests/Csla.Analyzers.Tests.csproj b/Source/Csla.Analyzers/Csla.Analyzers.Tests/Csla.Analyzers.Tests.csproj index 0d60550b85..739c2def8f 100644 --- a/Source/Csla.Analyzers/Csla.Analyzers.Tests/Csla.Analyzers.Tests.csproj +++ b/Source/Csla.Analyzers/Csla.Analyzers.Tests/Csla.Analyzers.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1;net462 + net48 false false false @@ -14,11 +14,11 @@ - + all runtime; build; native; contentfiles; analyzers - + diff --git a/Source/Csla.Analyzers/Csla.Analyzers/Csla.Analyzers.csproj b/Source/Csla.Analyzers/Csla.Analyzers/Csla.Analyzers.csproj index bf4bb6c34b..1a4301392a 100644 --- a/Source/Csla.Analyzers/Csla.Analyzers/Csla.Analyzers.csproj +++ b/Source/Csla.Analyzers/Csla.Analyzers/Csla.Analyzers.csproj @@ -11,7 +11,7 @@ - + diff --git a/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs b/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs index 06d17cbc5a..ae08fc9d48 100644 --- a/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs +++ b/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs @@ -8,6 +8,7 @@ //----------------------------------------------------------------------- using Csla.Core; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Http; using System; using System.Security.Claims; using System.Security.Principal; @@ -16,8 +17,9 @@ namespace Csla.AspNetCore.Blazor { /// - /// Application context manager that uses HttpContextAccessor when - /// resolving HttpContext to store context values. + /// Application context manager that adapts how to manage + /// per-user state and identity for server-rendered and + /// server-interactive Blazor modes. /// public class ApplicationContextManagerBlazor : IContextManager, IDisposable { @@ -42,14 +44,21 @@ public class ApplicationContextManagerBlazor : IContextManager, IDisposable /// protected ActiveCircuitState ActiveCircuitState { get; private set; } + /// + /// Gets or sets a reference to the current HttpContext. + /// + protected HttpContext HttpContext { get; set; } + /// /// Creates an instance of the object, initializing it /// with the required IServiceProvider. /// + /// IHttpContextAccessor service /// AuthenticationStateProvider service /// - public ApplicationContextManagerBlazor(AuthenticationStateProvider authenticationStateProvider, ActiveCircuitState activeCircuitState) + public ApplicationContextManagerBlazor(IHttpContextAccessor hca, AuthenticationStateProvider authenticationStateProvider, ActiveCircuitState activeCircuitState) { + HttpContext = hca.HttpContext; AuthenticationStateProvider = authenticationStateProvider; ActiveCircuitState = activeCircuitState; CurrentPrincipal = UnauthenticatedPrincipal; @@ -59,26 +68,37 @@ public ApplicationContextManagerBlazor(AuthenticationStateProvider authenticatio private void InitializeUser() { - Task task = default; - try - { - task = AuthenticationStateProvider.GetAuthenticationStateAsync(); - } - catch (InvalidOperationException ex) + if (ActiveCircuitState.CircuitExists) { - task = Task.FromResult(new AuthenticationState((ClaimsPrincipal)UnauthenticatedPrincipal)); - string message = ex.Message; - if (message.Contains(nameof(AuthenticationStateProvider.GetAuthenticationStateAsync)) - && message.Contains(nameof(IHostEnvironmentAuthenticationStateProvider.SetAuthenticationState))) + Task task; + try { - SetHostPrincipal(task); + task = AuthenticationStateProvider.GetAuthenticationStateAsync(); } - else + catch (InvalidOperationException ex) { - throw; + task = Task.FromResult(new AuthenticationState((ClaimsPrincipal)UnauthenticatedPrincipal)); + string message = ex.Message; + if (message.Contains(nameof(AuthenticationStateProvider.GetAuthenticationStateAsync)) + && message.Contains(nameof(IHostEnvironmentAuthenticationStateProvider.SetAuthenticationState))) + { + SetHostPrincipal(task); + } + else + { + throw; + } } + AuthenticationStateProvider_AuthenticationStateChanged(task); + } + else if (HttpContext is not null) + { + CurrentPrincipal = HttpContext.User; + } + else + { + throw new InvalidOperationException("HttpContext==null, !CircuitExists"); } - AuthenticationStateProvider_AuthenticationStateChanged(task); } private void AuthenticationStateProvider_AuthenticationStateChanged(Task task) @@ -106,7 +126,7 @@ private void AuthenticationStateProvider_AuthenticationStateChanged(Task public bool IsValid { - get { return ActiveCircuitState.CircuitExists; } + get { return HttpContext is not null || ActiveCircuitState.CircuitExists; } } /// @@ -132,15 +152,26 @@ public virtual void SetUser(IPrincipal principal) { if (!ReferenceEquals(CurrentPrincipal, principal)) { - if (principal is ClaimsPrincipal claimsPrincipal) + if (ActiveCircuitState.CircuitExists) + { + if (principal is ClaimsPrincipal claimsPrincipal) + { + SetHostPrincipal(Task.FromResult(new AuthenticationState(claimsPrincipal))); + } + else + { + throw new ArgumentException("typeof(principal) != ClaimsPrincipal"); + } + } + else if (HttpContext is not null) { - CurrentPrincipal = principal; - SetHostPrincipal(Task.FromResult(new AuthenticationState(claimsPrincipal))); + HttpContext.User = (ClaimsPrincipal)principal; } else { - throw new ArgumentException("typeof(principal) != ClaimsPrincipal"); + throw new InvalidOperationException("HttpContext==null, !CircuitExists"); } + CurrentPrincipal = principal; } } diff --git a/Source/Csla.AspNetCore/Csla.AspNetCore.csproj b/Source/Csla.AspNetCore/Csla.AspNetCore.csproj index f414b804e8..40897e985a 100644 --- a/Source/Csla.AspNetCore/Csla.AspNetCore.csproj +++ b/Source/Csla.AspNetCore/Csla.AspNetCore.csproj @@ -24,7 +24,7 @@ - + diff --git a/Source/Csla.Blazor.Test/ApplicationContextTests.cs b/Source/Csla.Blazor.Test/ApplicationContextTests.cs deleted file mode 100644 index 2cd53111bf..0000000000 --- a/Source/Csla.Blazor.Test/ApplicationContextTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.Extensions.DependencyInjection; -using System; -using Csla.Configuration; -using Csla.Core; -using Microsoft.AspNetCore.Components.Authorization; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Linq; - -namespace Csla.Blazor.Test -{ - [TestClass] - public class ApplicationContextTests - { -#if NET6_0_OR_GREATER - [TestMethod] - public void CorrectManagerChosen() - { - IServiceCollection services = new ServiceCollection(); - services.AddHttpContextAccessor(); - services.AddScoped(); - services.AddScoped(typeof(AuthenticationStateProvider), typeof(TestAuthenticationStateProvider)); - services.AddCsla(c => c - .AddAspNetCore() - .AddServerSideBlazor() - ); - IServiceProvider provider = services.BuildServiceProvider(); - var managers = provider.GetRequiredService>(); - Assert.IsTrue(managers.Count() == 2); - var blazorMgr = (Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor)managers.FirstOrDefault(mgr => mgr is Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor); - var httpMgr = (Csla.AspNetCore.ApplicationContextManagerHttpContext)managers.FirstOrDefault(mgr => mgr is Csla.AspNetCore.ApplicationContextManagerHttpContext); - Assert.IsNotNull(blazorMgr); - Assert.IsTrue(blazorMgr.IsStatefulContext); - Assert.IsFalse(blazorMgr.IsValid); //because no circuit exists - - - Assert.IsNotNull(httpMgr); - Assert.IsFalse(httpMgr.IsStatefulContext); - Assert.IsFalse(httpMgr.IsValid); //because no httpcontext exists - - //in this scenario the appliclication context should choose the asynclocal as the - var appContext = provider.GetRequiredService(); - Assert.IsNotNull(appContext); - Assert.IsTrue(appContext.ContextManager is Csla.Core.ApplicationContextManagerAsyncLocal); - - } -#endif - } - - public class TestAuthenticationStateProvider : AuthenticationStateProvider - { - public override Task GetAuthenticationStateAsync() - => Task.FromResult(null); - } -} diff --git a/Source/Csla.Blazor.Test/Csla.Blazor.Test.csproj b/Source/Csla.Blazor.Test/Csla.Blazor.Test.csproj index 4749a3e54a..7bb3809f3f 100644 --- a/Source/Csla.Blazor.Test/Csla.Blazor.Test.csproj +++ b/Source/Csla.Blazor.Test/Csla.Blazor.Test.csproj @@ -1,16 +1,16 @@ - netcoreapp3.1;net6.0 + net8.0 false Library - - - + + + diff --git a/Source/Csla.Blazor.WebAssembly/Csla.Blazor.WebAssembly.csproj b/Source/Csla.Blazor.WebAssembly/Csla.Blazor.WebAssembly.csproj index cdb5bb8c77..0c854e258d 100644 --- a/Source/Csla.Blazor.WebAssembly/Csla.Blazor.WebAssembly.csproj +++ b/Source/Csla.Blazor.WebAssembly/Csla.Blazor.WebAssembly.csproj @@ -30,8 +30,8 @@ - - + + diff --git a/Source/Csla.Blazor/Csla.Blazor.csproj b/Source/Csla.Blazor/Csla.Blazor.csproj index c7255e6a38..65ecd1b46c 100644 --- a/Source/Csla.Blazor/Csla.Blazor.csproj +++ b/Source/Csla.Blazor/Csla.Blazor.csproj @@ -1,4 +1,4 @@ - + netstandard2.1;net6.0;net7.0;net8.0 @@ -27,9 +27,9 @@ - - - + + + diff --git a/Source/Csla.Generators/cs/Csla.Generators.CSharp/Csla.Generators.CSharp.csproj b/Source/Csla.Generators/cs/Csla.Generators.CSharp/Csla.Generators.CSharp.csproj index cf123ec87e..adc0520c19 100644 --- a/Source/Csla.Generators/cs/Csla.Generators.CSharp/Csla.Generators.CSharp.csproj +++ b/Source/Csla.Generators/cs/Csla.Generators.CSharp/Csla.Generators.CSharp.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/Source/Csla.TestHelpers/Csla.TestHelpers.csproj b/Source/Csla.TestHelpers/Csla.TestHelpers.csproj index 258afb23fa..45c917c7a1 100644 --- a/Source/Csla.TestHelpers/Csla.TestHelpers.csproj +++ b/Source/Csla.TestHelpers/Csla.TestHelpers.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs b/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs index c86d73409f..0e6f6974f3 100644 --- a/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs +++ b/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs @@ -198,11 +198,11 @@ private async Task InvokePortal(string operation, Stream requestStream, Stream r DataPortalErrorInfo errorData = null; if (UseTextSerialization) { - Response.Headers.Add("Content-type", "application/base64,text/plain"); + Response.Headers["Content-type"] = "application/base64,text/plain"; } else { - Response.Headers.Add("Content-type", "application/octet-stream"); + Response.Headers["Content-type"] = "application/octet-stream"; } SetHttpResponseHeaders(Response); try diff --git a/Source/Csla/BusinessBase.cs b/Source/Csla/BusinessBase.cs index e15bbbe0d2..99244aae45 100644 --- a/Source/Csla/BusinessBase.cs +++ b/Source/Csla/BusinessBase.cs @@ -305,9 +305,7 @@ public event EventHandler Saved { add { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableSavedHandlers = (EventHandler) System.Delegate.Combine(_serializableSavedHandlers, value); else @@ -316,9 +314,7 @@ public event EventHandler Saved } remove { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableSavedHandlers = (EventHandler) System.Delegate.Remove(_serializableSavedHandlers, value); else diff --git a/Source/Csla/BusinessBindingListBase.cs b/Source/Csla/BusinessBindingListBase.cs index ef57fb2e1a..5cfc6840e4 100644 --- a/Source/Csla/BusinessBindingListBase.cs +++ b/Source/Csla/BusinessBindingListBase.cs @@ -1061,9 +1061,7 @@ public event EventHandler Saved { add { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableSavedHandlers = (EventHandler) System.Delegate.Combine(_serializableSavedHandlers, value); else @@ -1072,9 +1070,7 @@ public event EventHandler Saved } remove { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableSavedHandlers = (EventHandler) System.Delegate.Remove(_serializableSavedHandlers, value); else diff --git a/Source/Csla/Configuration/Abstraction/ConfigurationErrorsException.cs b/Source/Csla/Configuration/Abstraction/ConfigurationErrorsException.cs index 66ebbfa6d7..52a88b1609 100644 --- a/Source/Csla/Configuration/Abstraction/ConfigurationErrorsException.cs +++ b/Source/Csla/Configuration/Abstraction/ConfigurationErrorsException.cs @@ -43,17 +43,5 @@ public ConfigurationErrorsException(string message, Exception innerException) { } - - /// - /// Creates an instance of the object for serialization. - /// - /// Serialization context. - /// Serialization info. - protected ConfigurationErrorsException(System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - - } } } \ No newline at end of file diff --git a/Source/Csla/Core/BindableBase.cs b/Source/Csla/Core/BindableBase.cs index 774d953584..089b9d69e9 100644 --- a/Source/Csla/Core/BindableBase.cs +++ b/Source/Csla/Core/BindableBase.cs @@ -67,8 +67,7 @@ public event PropertyChangedEventHandler PropertyChanged protected virtual bool ShouldHandlerSerialize(PropertyChangedEventHandler value) { return value.Method.IsPublic && - value.Method.DeclaringType != null && - (value.Method.DeclaringType.IsSerializable || value.Method.IsStatic); + value.Method.DeclaringType != null; } /// @@ -264,8 +263,7 @@ protected virtual void OnPropertyChanging(IPropertyInfo propertyInfo) protected virtual bool ShouldHandlerSerialize(PropertyChangingEventHandler value) { return value.Method.IsPublic && - value.Method.DeclaringType != null && - (value.Method.DeclaringType.IsSerializable || value.Method.IsStatic); + value.Method.DeclaringType != null; } } } \ No newline at end of file diff --git a/Source/Csla/Core/BusinessBase.cs b/Source/Csla/Core/BusinessBase.cs index 9a5f9b7246..98b0ff7887 100644 --- a/Source/Csla/Core/BusinessBase.cs +++ b/Source/Csla/Core/BusinessBase.cs @@ -1406,31 +1406,14 @@ protected override void OnPropertyChanged(IPropertyInfo propertyInfo) #region Serialization Notification void ISerializationNotification.Deserialized() - { - OnDeserializedHandler(new System.Runtime.Serialization.StreamingContext()); - } - - [System.Runtime.Serialization.OnDeserialized] - private void OnDeserializedHandler(System.Runtime.Serialization.StreamingContext context) { BusinessRules.SetTarget(this); if (_fieldManager != null) FieldManager.SetPropertyList(this.GetType()); InitializeBusinessRules(); FieldDataDeserialized(); - - OnDeserialized(context); } - /// - /// This method is called on a newly deserialized object - /// after deserialization is complete. - /// - /// Serialization context object. - [EditorBrowsable(EditorBrowsableState.Advanced)] - protected virtual void OnDeserialized(System.Runtime.Serialization.StreamingContext context) - { } - #endregion #region Bubbling event Hooks diff --git a/Source/Csla/Core/ExtendedBindingList.cs b/Source/Csla/Core/ExtendedBindingList.cs index c012395e2f..b1eec2dca8 100644 --- a/Source/Csla/Core/ExtendedBindingList.cs +++ b/Source/Csla/Core/ExtendedBindingList.cs @@ -39,9 +39,7 @@ public event EventHandler RemovingItem { add { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableHandlers = (EventHandler) System.Delegate.Combine(_serializableHandlers, value); else @@ -50,9 +48,7 @@ public event EventHandler RemovingItem } remove { - if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + if (value.Method.IsPublic) _serializableHandlers = (EventHandler) System.Delegate.Remove(_serializableHandlers, value); else diff --git a/Source/Csla/Core/MobileDictionary.cs b/Source/Csla/Core/MobileDictionary.cs index 0cfbaed1f8..60b6625811 100644 --- a/Source/Csla/Core/MobileDictionary.cs +++ b/Source/Csla/Core/MobileDictionary.cs @@ -83,20 +83,6 @@ public bool Contains(K key) return base.ContainsKey(key); } -#if !(ANDROID || IOS) && !NETFX_CORE - /// - /// Creates an instance of the object for serialization. - /// - /// Serialization context. - /// Serialization info. - protected MobileDictionary(System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - DetermineTypes(); - } -#endif - private void DetermineTypes() { _keyIsMobile = typeof(Csla.Serialization.Mobile.IMobileObject).IsAssignableFrom(typeof(K)); diff --git a/Source/Csla/Core/UndoException.cs b/Source/Csla/Core/UndoException.cs index 0199b6d0b3..9580d5b996 100644 --- a/Source/Csla/Core/UndoException.cs +++ b/Source/Csla/Core/UndoException.cs @@ -62,30 +62,5 @@ public UndoException(string message, Exception ex) { } - -#if !NETFX_CORE && !IOS && !ANDROID - /// - /// Creates an instance of the object for serialization. - /// - /// Serialiation info object. - /// Serialization context object. - protected UndoException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - - } - - /// - /// Serializes the object. - /// - /// Serialiation info object. - /// Serialization context object. - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - - base.GetObjectData(info, context); - - } -#endif } } \ No newline at end of file diff --git a/Source/Csla/Csla.csproj b/Source/Csla/Csla.csproj index 6bf9e0aa3e..f1c35da4c2 100644 --- a/Source/Csla/Csla.csproj +++ b/Source/Csla/Csla.csproj @@ -58,12 +58,12 @@ - - - - - - + + + + + + diff --git a/Source/Csla/DataPortalException.cs b/Source/Csla/DataPortalException.cs index 00962cc7ea..a7a1180ff4 100644 --- a/Source/Csla/DataPortalException.cs +++ b/Source/Csla/DataPortalException.cs @@ -192,34 +192,5 @@ public override string StackTrace { get { return String.Format("{0}{1}{2}", _innerStackTrace, Environment.NewLine, base.StackTrace); } } - - /// - /// Creates an instance of the object for serialization. - /// - /// Serialization info object. - /// Serialization context object. - protected DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - _businessObject = info.GetValue("_businessObject", typeof(object)); - _innerStackTrace = info.GetString("_innerStackTrace"); - } - - /// - /// Serializes the object. - /// - /// Serialization info object. - /// Serialization context object. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] -#if !NET6_0_OR_GREATER - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] -#endif - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue("_businessObject", _businessObject); - info.AddValue("_innerStackTrace", _innerStackTrace); - } } } \ No newline at end of file diff --git a/Source/Csla/DynamicBindingListBase.cs b/Source/Csla/DynamicBindingListBase.cs index 2d6507ad82..7d042d0675 100644 --- a/Source/Csla/DynamicBindingListBase.cs +++ b/Source/Csla/DynamicBindingListBase.cs @@ -224,8 +224,7 @@ public event EventHandler Saved add { if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + value.Method.IsStatic) _serializableSavedHandlers = (EventHandler) System.Delegate.Combine(_serializableSavedHandlers, value); else @@ -235,8 +234,7 @@ public event EventHandler Saved remove { if (value.Method.IsPublic && - (value.Method.DeclaringType.IsSerializable || - value.Method.IsStatic)) + value.Method.IsStatic) _serializableSavedHandlers = (EventHandler) System.Delegate.Remove(_serializableSavedHandlers, value); else diff --git a/Source/Csla/PropertyLoadException.cs b/Source/Csla/PropertyLoadException.cs index baeea75fb0..dbeca932e5 100644 --- a/Source/Csla/PropertyLoadException.cs +++ b/Source/Csla/PropertyLoadException.cs @@ -33,26 +33,5 @@ public PropertyLoadException(string message) public PropertyLoadException(string message, Exception ex) : base(message, ex) { } - -#if !NETFX_CORE - /// - /// Creates an instance of the object for serialization. - /// - /// Serialiation info object. - /// Serialization context object. - protected PropertyLoadException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { } - - /// - /// Serializes the object. - /// - /// Serialiation info object. - /// Serialization context object. - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData(info, context); - } -#endif } } \ No newline at end of file diff --git a/Source/Csla/Reflection/CallMethodException.cs b/Source/Csla/Reflection/CallMethodException.cs index f75f7621d5..8def36f378 100644 --- a/Source/Csla/Reflection/CallMethodException.cs +++ b/Source/Csla/Reflection/CallMethodException.cs @@ -50,33 +50,5 @@ public CallMethodException(string message, Exception ex) { _innerStackTrace = ex.StackTrace; } - - /// - /// Creates an instance of the object for deserialization. - /// - /// Serialization info. - /// Serialiation context. - protected CallMethodException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - _innerStackTrace = info.GetString("_innerStackTrace"); - } - - - /// - /// Serializes the object. - /// - /// Serialization info. - /// Serialization context. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] -#if !NET6_0_OR_GREATER - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] -#endif - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue("_innerStackTrace", _innerStackTrace); - } } } \ No newline at end of file diff --git a/Source/Csla/Rules/ValidationException.cs b/Source/Csla/Rules/ValidationException.cs index 4f3014aced..dbccfbdd15 100644 --- a/Source/Csla/Rules/ValidationException.cs +++ b/Source/Csla/Rules/ValidationException.cs @@ -46,19 +46,5 @@ public ValidationException(string message, Exception innerException) { } - -#if !(ANDROID || IOS) && !NETFX_CORE - /// - /// Creates an instance of the object for serialization. - /// - /// Serialization context. - /// Serialization info. - protected ValidationException(System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - - } -#endif } } \ No newline at end of file diff --git a/Source/Csla/Security/CslaClaimsPrincipal.cs b/Source/Csla/Security/CslaClaimsPrincipal.cs index 891561b761..9368631f44 100644 --- a/Source/Csla/Security/CslaClaimsPrincipal.cs +++ b/Source/Csla/Security/CslaClaimsPrincipal.cs @@ -82,16 +82,6 @@ public CslaClaimsPrincipal(System.IO.BinaryReader reader) : base(reader) { } - /// - /// Creates an instance of the object from - /// BinaryFormatter or NDCS deserialization. - /// - /// Serialization context - /// Serialization info - protected CslaClaimsPrincipal(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { } - void IMobileObject.GetChildren(SerializationInfo info, MobileFormatter formatter) { } diff --git a/Source/Csla/Security/SecurityException.cs b/Source/Csla/Security/SecurityException.cs index 33faf3d797..ea5d4f2b1a 100644 --- a/Source/Csla/Security/SecurityException.cs +++ b/Source/Csla/Security/SecurityException.cs @@ -37,33 +37,6 @@ public SecurityException(string message) public SecurityException(string message, Exception innerException) : base(message, innerException) { } - -#if !(ANDROID || IOS) && !NETFX_CORE - /// - /// Creates an instance of the object for serialization. - /// - /// Serialiation info object. - /// Serialization context object. - protected SecurityException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - } - - /// - /// Serializes the object. - /// - /// Serialiation info object. - /// Serialization context object. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] -#if !NET6_0_OR_GREATER - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] -#endif - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData(info, context); - } -#endif } } diff --git a/Source/Csla/Serialization/Mobile/MobileFormatter.cs b/Source/Csla/Serialization/Mobile/MobileFormatter.cs index 0babc778a4..3d0c8030d3 100644 --- a/Source/Csla/Serialization/Mobile/MobileFormatter.cs +++ b/Source/Csla/Serialization/Mobile/MobileFormatter.cs @@ -145,10 +145,7 @@ public SerializationInfo SerializeObject(object obj) obj = new Security.CslaClaimsPrincipal(cp); thisType = obj.GetType(); } - if (!thisType.IsSerializable) - throw new InvalidOperationException( - string.Format(Resources.ObjectNotSerializableFormatted, thisType.FullName)); - if (!(obj is IMobileObject mobile)) + if (obj is not IMobileObject mobile) throw new InvalidOperationException( string.Format(Resources.MustImplementIMobileObject, thisType.Name)); diff --git a/Source/Csla/Server/DataPortalException.cs b/Source/Csla/Server/DataPortalException.cs index f64b9d36e4..7d506e0752 100644 --- a/Source/Csla/Server/DataPortalException.cs +++ b/Source/Csla/Server/DataPortalException.cs @@ -53,37 +53,5 @@ public DataPortalException( _innerStackTrace = ex.StackTrace; _result = result; } - -#if !(ANDROID || IOS) && !NETFX_CORE - /// - /// Creates an instance of the object for serialization. - /// - /// Serialiation info object. - /// Serialization context object. - protected DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - _result = (DataPortalResult)info.GetValue( - "_result", typeof(DataPortalResult)); - _innerStackTrace = info.GetString("_innerStackTrace"); - } - - /// - /// Serializes the object. - /// - /// Serialiation info object. - /// Serialization context object. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] -#if !NET6_0_OR_GREATER - [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] - [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] -#endif - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue("_result", _result); - info.AddValue("_innerStackTrace", _innerStackTrace); - } -#endif } } \ No newline at end of file diff --git a/Source/Csla/Server/GenericBusinessException.cs b/Source/Csla/Server/GenericBusinessException.cs index fe6c298cb2..76a5fe0fe8 100644 --- a/Source/Csla/Server/GenericBusinessException.cs +++ b/Source/Csla/Server/GenericBusinessException.cs @@ -96,47 +96,6 @@ public GenericBusinessException(Exception wrappedException, Exception innerExcep _type = wrappedException.GetType().ToString(); } - - /// - /// Initializes a new instance of the class. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - /// The parameter is null. - /// The class name is null or is zero (0). - public GenericBusinessException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - - _data = (IDictionary)info.GetValue("_data", typeof(IDictionary)); - _stackTrace = info.GetString("_stackTrace"); - _type = info.GetString("_type"); - } - - /// - /// When overridden in a derived class, sets the with information about the exception. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - /// The parameter is a null reference (Nothing in Visual Basic). - /// - /// - /// - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] -#if !NET6_0_OR_GREATER - [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] - [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] -#endif - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - - info.AddValue("_data", _data); - info.AddValue("_stackTrace", _stackTrace); - info.AddValue("_type", _type); - } - /// /// Returns a that represents this instance. /// diff --git a/Source/csla.netcore.test/Basic/GrandChild.cs b/Source/csla.netcore.test/Basic/GrandChild.cs index 96ca14606d..dfdd2d4058 100644 --- a/Source/csla.netcore.test/Basic/GrandChild.cs +++ b/Source/csla.netcore.test/Basic/GrandChild.cs @@ -66,11 +66,5 @@ internal void Update(IDbTransaction tr) MarkOld(); } } - - protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context) - { - base.OnDeserialized(context); - TestResults.Add("GCDeserialized", "GC Deserialized"); - } } } \ No newline at end of file diff --git a/Source/csla.netcore.test/Basic/Root.cs b/Source/csla.netcore.test/Basic/Root.cs index f9ca20d459..c641cad07f 100644 --- a/Source/csla.netcore.test/Basic/Root.cs +++ b/Source/csla.netcore.test/Basic/Root.cs @@ -100,11 +100,6 @@ protected void DataPortal_Delete(object criteria) TestResults.Add("Root", "Deleted"); } - protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context) - { - TestResults.Add("Deserialized", "root Deserialized"); - } - protected override void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e) { TestResults.Add("dpinvoke", "Invoked"); diff --git a/Source/csla.netcore.test/BasicModern/BasicModernTests.cs b/Source/csla.netcore.test/BasicModern/BasicModernTests.cs index fa26c3b895..adb410a120 100644 --- a/Source/csla.netcore.test/BasicModern/BasicModernTests.cs +++ b/Source/csla.netcore.test/BasicModern/BasicModernTests.cs @@ -187,28 +187,44 @@ public void RootChangedMetastateEventsChild() Assert.IsTrue(changed.Contains("IsSavable"), "IsSavable after add"); Assert.IsFalse(changed.Contains("IsNew"), "IsNew after add"); Assert.IsFalse(changed.Contains("IsDeleted"), "IsDeleted after add"); + } + + [TestMethod] + public void RootChangedMetastateEventsChildAfterSave() + { + Csla.ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml; + var graph = CreateRoot(); + var changed = new List(); + graph.Name = "abc"; + var child = graph.Children.AddNew(); + child.Id = 123; + child.Name = "xyz"; graph = graph.Save(); + changed.Clear(); graph.PropertyChanged += (o, e) => { changed.Add(e.PropertyName); }; - - Assert.IsFalse(graph.IsDirty, "IsDirty should be false"); + graph.ChildChanged += (o, e) => + { + if (e.ChildObject is not null) + changed.Add($"{e.ChildObject.GetType()}-{e.PropertyChangedArgs.PropertyName}"); + }; graph.Children[0].Name = "mnop"; Assert.IsTrue(graph.IsDirty, "IsDirty should be true"); - Assert.IsFalse(changed.Contains("Children"), "Children after add"); - Assert.IsTrue(changed.Contains("IsDirty"), "IsDirty after add"); - Assert.IsFalse(changed.Contains("IsSelfDirty"), "IsSelfDirty after add"); - Assert.IsTrue(changed.Contains("IsValid"), "IsValid after add"); - Assert.IsFalse(changed.Contains("IsSelfValid"), "IsSelfValid after add"); - Assert.IsTrue(changed.Contains("IsSavable"), "IsSavable after add"); - Assert.IsFalse(changed.Contains("IsNew"), "IsNew after add"); - Assert.IsFalse(changed.Contains("IsDeleted"), "IsDeleted after add"); + Assert.IsFalse(changed.Contains("Children"), "Children after edit"); + Assert.IsTrue(changed.Contains("IsDirty"), "IsDirty after edit"); + Assert.IsFalse(changed.Contains("IsSelfDirty"), "IsSelfDirty after edit"); + Assert.IsTrue(changed.Contains("IsValid"), "IsValid after edit"); + Assert.IsFalse(changed.Contains("IsSelfValid"), "IsSelfValid after edit"); + Assert.IsTrue(changed.Contains("IsSavable"), "IsSavable after edit"); + Assert.IsFalse(changed.Contains("IsNew"), "IsNew after edit"); + Assert.IsFalse(changed.Contains("IsDeleted"), "IsDeleted after edit"); } private Root CreateRoot() diff --git a/Source/csla.netcore.test/Server/Interceptors/GrandChild.cs b/Source/csla.netcore.test/Server/Interceptors/GrandChild.cs index 0fc8f6ab8b..d9099004cf 100644 --- a/Source/csla.netcore.test/Server/Interceptors/GrandChild.cs +++ b/Source/csla.netcore.test/Server/Interceptors/GrandChild.cs @@ -68,11 +68,5 @@ internal void Update(IDbTransaction tr) MarkOld(); } } - - protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context) - { - base.OnDeserialized(context); - TestResults.Add("GCDeserialized", "GC Deserialized"); - } } } \ No newline at end of file diff --git a/Source/csla.netcore.test/Server/Interceptors/Root.cs b/Source/csla.netcore.test/Server/Interceptors/Root.cs index 9df59afdd3..1677e4ef3f 100644 --- a/Source/csla.netcore.test/Server/Interceptors/Root.cs +++ b/Source/csla.netcore.test/Server/Interceptors/Root.cs @@ -97,10 +97,6 @@ protected void DataPortal_Delete(object criteria) { } - protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context) - { - } - protected override void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e) { } diff --git a/Source/csla.netcore.test/csla.netcore.test.csproj b/Source/csla.netcore.test/csla.netcore.test.csproj index 8291329cd4..107cda0949 100644 --- a/Source/csla.netcore.test/csla.netcore.test.csproj +++ b/Source/csla.netcore.test/csla.netcore.test.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net8.0 false true ..\Csla\CslaKey.snk @@ -9,10 +9,10 @@ - - - - + + + +