From aa00865dbfb92a4bdec6177d671d651ffdfbcf07 Mon Sep 17 00:00:00 2001
From: Ruthlessist <30370418+Ruthlessist@users.noreply.github.com>
Date: Fri, 30 Dec 2022 15:04:35 +0800
Subject: [PATCH 1/8] fix #279 (#295)

* fix #279

* Change AspectExceptionWrapper lifetime to Transient
---
 .../DynamicProxy/AspectExceptionWrapper.cs    | 19 ++++----
 .../DynamicProxy/IAspectExceptionWrapper.cs   |  4 +-
 .../DependencyInjection/ServiceContext.cs     |  2 +-
 .../DynamicProxy/AspectActivator.cs           | 43 ++++++++++++-------
 .../ContainerBuilderExtensions.cs             |  2 +-
 .../ServiceCollectionExtensions.cs            |  2 +-
 .../ContainerBuilderExtensions.cs             |  2 +-
 .../AspectCoreFacility.cs                     |  2 +-
 8 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs b/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
index fbc6d395..4633c6cd 100644
--- a/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
+++ b/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Runtime.ExceptionServices;
 using AspectCore.Configuration;
 
 namespace AspectCore.DynamicProxy
@@ -7,25 +8,27 @@ namespace AspectCore.DynamicProxy
     public class AspectExceptionWrapper : IAspectExceptionWrapper
     {
         private readonly IAspectConfiguration _configuration;
+        private ExceptionDispatchInfo _exceptionInfo;
 
         public AspectExceptionWrapper(IAspectConfiguration configuration)
         {
             _configuration = configuration;
         }
 
-        public Exception Wrap(AspectContext aspectContext, Exception exception)
+        public void Wrap(AspectContext aspectContext, Exception exception)
         {
-            if (!_configuration.ThrowAspectException)
+            if (!_configuration.ThrowAspectException || exception is AspectInvocationException _)
             {
-                return exception;
+                _exceptionInfo = ExceptionDispatchInfo.Capture(exception);
+                return;
             }
 
-            if (exception is AspectInvocationException aspectInvocationException)
-            {
-                return aspectInvocationException;
-            }
+            _exceptionInfo = ExceptionDispatchInfo.Capture(new AspectInvocationException(aspectContext, exception));
+        }
 
-            return new AspectInvocationException(aspectContext, exception);
+        public void ThrowIfFailed()
+        {
+            _exceptionInfo?.Throw();
         }
     }
 }
\ No newline at end of file
diff --git a/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs b/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
index c6531701..ec85de6f 100644
--- a/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
+++ b/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
@@ -4,6 +4,8 @@ namespace AspectCore.DynamicProxy
 {
     public interface IAspectExceptionWrapper
     {
-        Exception Wrap(AspectContext aspectContext, Exception exception);
+        void Wrap(AspectContext aspectContext, Exception exception);
+
+        void ThrowIfFailed();
     }
 }
\ No newline at end of file
diff --git a/src/AspectCore.Core/DependencyInjection/ServiceContext.cs b/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
index 5b4604bd..469e4691 100644
--- a/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
+++ b/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
@@ -100,7 +100,7 @@ private void AddInternalServices()
             if (!Contains(typeof(IAspectCachingProvider)))
                 Singletons.AddType<IAspectCachingProvider, AspectCachingProvider>();
             if (!Contains(typeof(IAspectExceptionWrapper)))
-                Singletons.AddType<IAspectExceptionWrapper, AspectExceptionWrapper>();
+                Transients.AddType<IAspectExceptionWrapper, AspectExceptionWrapper>();
         }
 
         public int Count => _collection.Count;
diff --git a/src/AspectCore.Core/DynamicProxy/AspectActivator.cs b/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
index a6e1459c..7a68e551 100644
--- a/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
+++ b/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
@@ -1,8 +1,6 @@
-﻿using System;
-using System.Diagnostics;
+﻿using AspectCore.Core.Utils;
+using System;
 using System.Threading.Tasks;
-using AspectCore.Core.Utils;
-using AspectCore.Utils;
 
 namespace AspectCore.DynamicProxy
 {
@@ -29,7 +27,10 @@ public TResult Invoke<TResult>(AspectActivatorContext activatorContext)
                 var aspectBuilder = _aspectBuilderFactory.Create(context);
                 var task = aspectBuilder.Build()(context);
                 if (task.IsFaulted)
-                    throw _aspectExceptionWrapper.Wrap(context, task.Exception.InnerException);
+                {
+                    _aspectExceptionWrapper.Wrap(context, task.Exception.InnerException);
+                    return default;
+                }
                 if (!task.IsCompleted)
                 {
                     // try to avoid potential deadlocks.
@@ -41,10 +42,12 @@ public TResult Invoke<TResult>(AspectActivatorContext activatorContext)
             }
             catch (Exception ex)
             {
-                throw _aspectExceptionWrapper.Wrap(context, ex);
+                _aspectExceptionWrapper.Wrap(context, ex);
+                return default;
             }
             finally
             {
+                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
@@ -59,7 +62,8 @@ public async Task<TResult> InvokeTask<TResult>(AspectActivatorContext activatorC
 
                 if (invoke.IsFaulted)
                 {
-                    throw _aspectExceptionWrapper.Wrap(context, invoke.Exception?.InnerException);
+                    _aspectExceptionWrapper.Wrap(context, invoke.Exception.InnerException);
+                    return default;
                 }
 
                 if (!invoke.IsCompleted)
@@ -70,22 +74,25 @@ public async Task<TResult> InvokeTask<TResult>(AspectActivatorContext activatorC
                 switch (context.ReturnValue)
                 {
                     case null:
-                        return default(TResult);
+                        return default;
                     case Task<TResult> taskWithResult:
                         return taskWithResult.Result;
                     case Task _:
-                        return default(TResult);
+                        return default;
                     default:
-                        throw _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
+                        _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
                             $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(Task<TResult>)}'."));
+                        return default;
                 }
             }
             catch (Exception ex)
             {
-                throw _aspectExceptionWrapper.Wrap(context, ex);
+                _aspectExceptionWrapper.Wrap(context, ex);
+                return default;
             }
             finally
             {
+                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
@@ -100,7 +107,8 @@ public async ValueTask<TResult> InvokeValueTask<TResult>(AspectActivatorContext
                 
                 if (invoke.IsFaulted)
                 {
-                    throw _aspectExceptionWrapper.Wrap(context, invoke.Exception?.InnerException);
+                    _aspectExceptionWrapper.Wrap(context, invoke.Exception.InnerException);
+                    return default;
                 }
                 
                 if (!invoke.IsCompleted)
@@ -111,22 +119,25 @@ public async ValueTask<TResult> InvokeValueTask<TResult>(AspectActivatorContext
                 switch (context.ReturnValue)
                 {
                     case null:
-                        return default(TResult);
+                        return default;
                     case ValueTask<TResult> taskWithResult:
                         return taskWithResult.Result;
                     case ValueTask task:
-                        return default(TResult);
+                        return default;
                     default:
-                        throw _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
+                        _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
                             $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(ValueTask<TResult>)}'."));
+                        return default;
                 }
             }
             catch (Exception ex)
             {
-                throw _aspectExceptionWrapper.Wrap(context, ex);
+                _aspectExceptionWrapper.Wrap(context, ex);
+                return default;
             }
             finally
             {
+                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
diff --git a/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs b/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
index b371be1b..20954e5f 100644
--- a/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
+++ b/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
@@ -58,7 +58,7 @@ public static ContainerBuilder RegisterDynamicProxy(this ContainerBuilder contai
             containerBuilder.RegisterType<AspectBuilderFactory>().As<IAspectBuilderFactory>().SingleInstance();
             containerBuilder.RegisterType<ProxyTypeGenerator>().As<IProxyTypeGenerator>().SingleInstance();
             containerBuilder.RegisterType<AspectCachingProvider>().As<IAspectCachingProvider>().SingleInstance();
-            containerBuilder.RegisterType<AspectExceptionWrapper>().As<IAspectExceptionWrapper>().SingleInstance();
+            containerBuilder.RegisterType<AspectExceptionWrapper>().As<IAspectExceptionWrapper>().InstancePerDependency();
 
             //全局注册中间件
             containerBuilder.ComponentRegistryBuilder.Registered += (sender, args) =>
diff --git a/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs b/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
index d362180a..b79df31e 100644
--- a/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
+++ b/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
@@ -59,7 +59,7 @@ internal static IServiceCollection TryAddDynamicProxyServices(this IServiceColle
             services.TryAddSingleton<IAspectBuilderFactory, AspectBuilderFactory>();
             services.TryAddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>();
             services.TryAddSingleton<IAspectCachingProvider, AspectCachingProvider>();
-            services.TryAddSingleton<IAspectExceptionWrapper, AspectExceptionWrapper>();
+            services.TryAddTransient<IAspectExceptionWrapper, AspectExceptionWrapper>();
 
             services.AddSingleton<IInterceptorSelector, ConfigureInterceptorSelector>();
             services.AddSingleton<IInterceptorSelector, AttributeInterceptorSelector>();
diff --git a/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs b/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
index 77e36ac4..7f40cbe1 100644
--- a/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
+++ b/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
@@ -73,7 +73,7 @@ public static IServiceContainer RegisterDynamicProxy(this IServiceContainer cont
                 .AddSingleton<IAspectBuilderFactory, AspectBuilderFactory>()
                 .AddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>()
                 .AddSingleton<IAspectCachingProvider, AspectCachingProvider>()
-                .AddSingleton<IAspectExceptionWrapper, AspectExceptionWrapper>();
+                .AddTransient(typeof(IAspectExceptionWrapper), typeof(AspectExceptionWrapper));
 
             var aspectValidator = new AspectValidatorBuilder(aspectConfig).Build();
             container.Decorate(aspectValidator.CreateDecorator());
diff --git a/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs b/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
index 4da64114..95d807aa 100644
--- a/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
+++ b/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
@@ -36,7 +36,7 @@ public void Init(IKernel kernel, IConfiguration facilityConfig)
                 Component.For<IInterceptorCollector>().ImplementedBy<InterceptorCollector>().LifestyleSingleton(),
                 Component.For<IAspectContextFactory>().ImplementedBy<AspectContextFactory>().LifestyleSingleton(),
                 Component.For<IAspectCachingProvider>().ImplementedBy<AspectCachingProvider>().LifestyleSingleton(),
-                Component.For<IAspectExceptionWrapper>().ImplementedBy<AspectExceptionWrapper>().LifestyleSingleton(),
+                Component.For<IAspectExceptionWrapper>().ImplementedBy<AspectExceptionWrapper>().LifestyleTransient(),
                 Component.For<IAspectActivatorFactory>().ImplementedBy<AspectActivatorFactory>().LifestyleSingleton(),
                 Component.For<IAspectValidatorBuilder>().ImplementedBy<AspectValidatorBuilder>().LifestyleSingleton(),
                 Component.For<IPropertyInjectorFactory>().ImplementedBy<PropertyInjectorFactory>().LifestyleSingleton(),

From 09df58c20ce561c1693f580d33de512f32aee189 Mon Sep 17 00:00:00 2001
From: Gilberto Alexandre <gibawa-github@yahoo.com>
Date: Thu, 23 Feb 2023 11:42:11 -0300
Subject: [PATCH 2/8] Update Predicates.cs (#300)

Without the given treatment, entities without a namespace (global), generate an error at startup when creating the ServiceProvider
---
 src/AspectCore.Core/Configuration/Predicates.cs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/AspectCore.Core/Configuration/Predicates.cs b/src/AspectCore.Core/Configuration/Predicates.cs
index bc77bff7..4f2a2682 100644
--- a/src/AspectCore.Core/Configuration/Predicates.cs
+++ b/src/AspectCore.Core/Configuration/Predicates.cs
@@ -10,8 +10,10 @@ public static AspectPredicate ForNameSpace(string nameSpace)
             {
                 throw new ArgumentNullException(nameof(nameSpace));
             }
-
-            return method => method.DeclaringType.Namespace.Matches(nameSpace);
+            
+            return method => nameSpace == method.DeclaringType.Namespace ||
+                             (method.DeclaringType.Namespace != null && 
+                              method.DeclaringType.Namespace.Matches(nameSpace));
         }
 
         public static AspectPredicate ForService(string service)
@@ -84,4 +86,4 @@ public static AspectPredicate Implement(Type baseOrInterfaceType)
             return methodInfo => baseOrInterfaceType.IsAssignableFrom(methodInfo.DeclaringType);
         }
     }
-}
\ No newline at end of file
+}

From 47793df011037ddf0efdb04aa5246c2d409750b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=95=BF=E7=A9=BAX?= <584880422@qq.com>
Date: Tue, 4 Apr 2023 09:44:17 +0800
Subject: [PATCH 3/8] =?UTF-8?q?Update=200.AOP=E7=AE=80=E5=8D=95=E4=BB=8B?=
 =?UTF-8?q?=E7=BB=8D.md=20(#304)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 "docs/0.AOP\347\256\200\345\215\225\344\273\213\347\273\215.md" | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git "a/docs/0.AOP\347\256\200\345\215\225\344\273\213\347\273\215.md" "b/docs/0.AOP\347\256\200\345\215\225\344\273\213\347\273\215.md"
index f07df071..70b3099e 100644
--- "a/docs/0.AOP\347\256\200\345\215\225\344\273\213\347\273\215.md"
+++ "b/docs/0.AOP\347\256\200\345\215\225\344\273\213\347\273\215.md"
@@ -41,7 +41,7 @@ AOP 实现会采用一些常见方法：
 
     dotnet 框架代表： [PostSharp](https://www.postsharp.net/aop.net)
 
-* 代码拦截，或者叫 动态代理
+* 代码拦截，或者叫 动态代理、动态编织、代码劫持
 
     在运行时在内存中“临时”生成 AOP 动态代理类，因此也被称为运行时增强或动态代理。
 

From b479bf327119df644c4908ea8e0ab021c5ec9e55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B2=89=E7=9D=A1=E7=9A=84=E6=9C=A8=E6=9C=A8=E5=A4=95?=
 <ms27946@163.com>
Date: Sat, 6 May 2023 17:55:13 +0800
Subject: [PATCH 4/8] fix reflect constructor error when ValueTupe's elements
 more than 7 (#307)

* fix: create instance of tuple/valuetuple exception when parameters number more than 7

* fix: add valuetuple more than 7 elements unit test
---
 .../Program.cs                                | 12 +--
 .../Extensions/TypeExtensions.cs              | 17 ++++
 .../ParameterReflector.cs                     |  7 +-
 .../ValueTupleMorethan7ElementsTests.cs       | 83 +++++++++++++++++++
 4 files changed, 113 insertions(+), 6 deletions(-)
 create mode 100644 tests/AspectCore.Extensions.DependencyInjection.Test/Issues/ValueTupleMorethan7ElementsTests.cs

diff --git a/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/Program.cs b/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/Program.cs
index 424402a5..6c999d50 100644
--- a/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/Program.cs
+++ b/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/Program.cs
@@ -1,4 +1,6 @@
 ﻿using System;
+using System.Linq;
+using System.Reflection;
 using AspectCore.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection;
 
@@ -13,11 +15,11 @@ static void Main(string[] args)
             services.AddTransient<ILogger, ConsoleLogger>();
             services.AddTransient<ISampleService, SampleService>();
             var serviceProvider = services.BuildServiceContextProvider();
-//            var container = services.ToServiceContext();
-//            container.AddType<ILogger, ConsoleLogger>();
-//            container.AddType<ISampleService, SampleService>();
-//            var serviceResolver = container.Build();
-//            var sampleService = serviceResolver.Resolve<ISampleService>();
+            //            var container = services.ToServiceContext();
+            //            container.AddType<ILogger, ConsoleLogger>();
+            //            container.AddType<ISampleService, SampleService>();
+            //            var serviceResolver = container.Build();
+            //            var sampleService = serviceResolver.Resolve<ISampleService>();
             var sampleService = serviceProvider.GetService<ISampleService>();
             sampleService.Invoke();
             Console.ReadKey();
diff --git a/src/AspectCore.Extensions.Reflection/Extensions/TypeExtensions.cs b/src/AspectCore.Extensions.Reflection/Extensions/TypeExtensions.cs
index f873e730..ded262fd 100644
--- a/src/AspectCore.Extensions.Reflection/Extensions/TypeExtensions.cs
+++ b/src/AspectCore.Extensions.Reflection/Extensions/TypeExtensions.cs
@@ -2,6 +2,7 @@
 using System.Collections.Concurrent;
 using System.Linq;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
 
 namespace AspectCore.Extensions.Reflection
@@ -181,5 +182,21 @@ public static bool IsNullableType(this Type type)
             return type.GetTypeInfo().IsGenericType &&
                    type.GetGenericTypeDefinition() == typeof(Nullable<>);
         }
+
+        public static bool IsTupleType(this Type type)
+        {
+            if (type is null)
+            {
+                throw new ArgumentNullException(nameof(type));
+            }
+#if NET461
+            return false;
+#elif NETSTANDARD2_0
+            return false;
+#else
+            return type.IsGenericType && typeof(ITuple).IsAssignableFrom(type.GetTypeInfo().GetGenericTypeDefinition());
+#endif
+
+        }
     }
 }
\ No newline at end of file
diff --git a/src/AspectCore.Extensions.Reflection/ParameterReflector.cs b/src/AspectCore.Extensions.Reflection/ParameterReflector.cs
index c7d4cb9b..4bda5174 100644
--- a/src/AspectCore.Extensions.Reflection/ParameterReflector.cs
+++ b/src/AspectCore.Extensions.Reflection/ParameterReflector.cs
@@ -1,6 +1,7 @@
 ﻿using System;
 using System.Linq;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 
 namespace AspectCore.Extensions.Reflection
 {
@@ -24,7 +25,11 @@ public partial class ParameterReflector : ICustomAttributeReflectorProvider
         private ParameterReflector(ParameterInfo reflectionInfo)
         {
             _reflectionInfo = reflectionInfo ?? throw new ArgumentNullException(nameof(reflectionInfo));
-            _customAttributeReflectors = _reflectionInfo.CustomAttributes.Select(data => CustomAttributeReflector.Create(data)).ToArray();
+
+            if (!reflectionInfo.ParameterType.IsTupleType())
+            {
+                _customAttributeReflectors = _reflectionInfo.CustomAttributes.Select(data => CustomAttributeReflector.Create(data)).ToArray();
+            }
             HasDeflautValue = reflectionInfo.HasDefaultValueByAttributes();
             if (HasDeflautValue)
             {
diff --git a/tests/AspectCore.Extensions.DependencyInjection.Test/Issues/ValueTupleMorethan7ElementsTests.cs b/tests/AspectCore.Extensions.DependencyInjection.Test/Issues/ValueTupleMorethan7ElementsTests.cs
new file mode 100644
index 00000000..b695220d
--- /dev/null
+++ b/tests/AspectCore.Extensions.DependencyInjection.Test/Issues/ValueTupleMorethan7ElementsTests.cs
@@ -0,0 +1,83 @@
+﻿using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace AspectCore.Extensions.DependencyInjection.Test.Issues
+{
+    // https://github.com/dotnetcore/AspectCore-Framework/issues/305
+    public class ValueTupleMorethan7ElementsTests
+    {
+        [Fact]
+        public void ValueTupleMorethan7Elements_Constructor_Test()
+        {
+            var services = new ServiceCollection();
+            services.AddScoped<ITestService, TestService>();
+            var serviceProvider = services.BuildServiceContextProvider();
+            var testService = serviceProvider.GetService<ITestService>();
+            Assert.NotNull(testService);
+
+            var (a, b, c, d, e, f, g, h) = testService.Wrap(("a", "b", "c", "d", "e", "f", "g", "h"));
+            Assert.Equal("a", a);
+            Assert.Equal("b", b);
+            Assert.Equal("c", c);
+            Assert.Equal("d", d);
+            Assert.Equal("e", e);
+            Assert.Equal("f", f);
+            Assert.Equal("g", g);
+            Assert.Equal("h", h);
+        }
+        public interface ITestService
+        {
+            //void Update((string, string, string, string, string, string, string) tupleKey);
+            void Update((string a, string b, string c, string d, string e, string f, string g, string h) tupleKey);
+            (string a, string b, string c, string d, string e, string f, string g, string h) Wrap((string a, string b, string c, string d, string e, string f, string g, string h) tupleKey);
+            //void Update2((string a, string b, string c, string d, string e, string f, string g) tupleKey);
+            //void Update3((string a, string b, string c, string d, string e, string f, string g, string h, (string i, string j)) tupleKey);
+        }
+
+        public class TestService : ITestService
+        {
+            //public void Update((string, string, string, string, string, string, string) tupleKey)
+            //{
+
+            //}
+            public void Update((string a, string b, string c, string d, string e, string f, string g, string h) tupleKey)
+            {
+            }
+
+            public (string a, string b, string c, string d, string e, string f, string g, string h) Wrap((string a, string b, string c, string d, string e, string f, string g, string h) tupleKey)
+            {
+                return tupleKey;
+            }
+
+            //public void Update2((string a, string b, string c, string d, string e, string f, string g) tupleKey)
+            //{
+
+            //}
+
+            //public void Update3((string a, string b, string c, string d, string e, string f, string g, string h, (string i, string j)) tupleKey)
+            //{
+
+            //}
+
+            //public void Update6((string a, string b, string c, string d, string e, string f, string g, (string h, string i, string j) ff) tupleKey)
+            //{
+
+            //}
+
+            //public void Update4((string, string, string, string, string, string, string) tupleKey)
+            //{
+
+            //}
+
+            //public void Update5((string, string, string, string, string, string, string, string, string) tupleKey)
+            //{
+
+            //}
+        }
+    }
+}

From cddd61616941cf5e756f235ce0a763b7e0f5cac3 Mon Sep 17 00:00:00 2001
From: PurplestViper <30370418+PurplestViper@users.noreply.github.com>
Date: Tue, 23 May 2023 17:38:38 +0800
Subject: [PATCH 5/8] =?UTF-8?q?#279,=20#295=20=E4=BB=8D=E6=9C=89=E9=97=AE?=
 =?UTF-8?q?=E9=A2=98=EF=BC=8C=E9=87=8D=E6=9E=84=20(#306)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../DynamicProxy/AspectExceptionWrapper.cs    |  34 ----
 .../AspectInvalidCastException.cs             |   7 +
 .../AspectInvalidOperationException.cs        |   7 +
 .../DynamicProxy/AspectInvocationException.cs |   6 +-
 .../DynamicProxy/IAspectExceptionWrapper.cs   |  11 --
 .../DependencyInjection/ServiceContext.cs     |  10 +-
 .../DynamicProxy/AspectActivator.cs           |  49 +++---
 .../DynamicProxy/AspectActivatorFactory.cs    |  11 +-
 .../AspectContextRuntimeExtensions.cs         |   2 +-
 .../ContainerBuilderExtensions.cs             |  16 +-
 .../ServiceCollectionExtensions.cs            |   9 +-
 .../ContainerBuilderExtensions.cs             |  12 +-
 .../AspectCoreFacility.cs                     |   9 +-
 .../DynamicProxyInterceptor.cs                |  16 +-
 .../ThrowExceptionDirectlyTests.cs            | 154 ++++++++++++++++++
 15 files changed, 232 insertions(+), 121 deletions(-)
 delete mode 100644 src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
 create mode 100644 src/AspectCore.Abstractions/DynamicProxy/AspectInvalidCastException.cs
 create mode 100644 src/AspectCore.Abstractions/DynamicProxy/AspectInvalidOperationException.cs
 delete mode 100644 src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
 create mode 100644 tests/AspectCore.Tests/DynamicProxy/ThrowExceptionDirectlyTests.cs

diff --git a/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs b/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
deleted file mode 100644
index 4633c6cd..00000000
--- a/src/AspectCore.Abstractions/DynamicProxy/AspectExceptionWrapper.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using System.Runtime.ExceptionServices;
-using AspectCore.Configuration;
-
-namespace AspectCore.DynamicProxy
-{
-    [NonAspect]
-    public class AspectExceptionWrapper : IAspectExceptionWrapper
-    {
-        private readonly IAspectConfiguration _configuration;
-        private ExceptionDispatchInfo _exceptionInfo;
-
-        public AspectExceptionWrapper(IAspectConfiguration configuration)
-        {
-            _configuration = configuration;
-        }
-
-        public void Wrap(AspectContext aspectContext, Exception exception)
-        {
-            if (!_configuration.ThrowAspectException || exception is AspectInvocationException _)
-            {
-                _exceptionInfo = ExceptionDispatchInfo.Capture(exception);
-                return;
-            }
-
-            _exceptionInfo = ExceptionDispatchInfo.Capture(new AspectInvocationException(aspectContext, exception));
-        }
-
-        public void ThrowIfFailed()
-        {
-            _exceptionInfo?.Throw();
-        }
-    }
-}
\ No newline at end of file
diff --git a/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidCastException.cs b/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidCastException.cs
new file mode 100644
index 00000000..003c5778
--- /dev/null
+++ b/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidCastException.cs
@@ -0,0 +1,7 @@
+﻿namespace AspectCore.DynamicProxy
+{
+    public class AspectInvalidCastException : AspectInvocationException
+    {
+        public AspectInvalidCastException(AspectContext aspectContext, string message) : base(aspectContext, message) { }
+    }
+}
\ No newline at end of file
diff --git a/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidOperationException.cs b/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidOperationException.cs
new file mode 100644
index 00000000..a9cc5def
--- /dev/null
+++ b/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidOperationException.cs
@@ -0,0 +1,7 @@
+﻿namespace AspectCore.DynamicProxy
+{
+    public class AspectInvalidOperationException : AspectInvocationException
+    {
+        public AspectInvalidOperationException(AspectContext aspectContext, string message) : base(aspectContext, message) { }
+    }
+}
\ No newline at end of file
diff --git a/src/AspectCore.Abstractions/DynamicProxy/AspectInvocationException.cs b/src/AspectCore.Abstractions/DynamicProxy/AspectInvocationException.cs
index 3b89f9ea..ed4e6471 100644
--- a/src/AspectCore.Abstractions/DynamicProxy/AspectInvocationException.cs
+++ b/src/AspectCore.Abstractions/DynamicProxy/AspectInvocationException.cs
@@ -6,8 +6,12 @@ public class AspectInvocationException : Exception
     {
         public AspectContext AspectContext { get; }
 
+        public AspectInvocationException(AspectContext aspectContext, string message) : this(aspectContext, message, null) { }
+
         public AspectInvocationException(AspectContext aspectContext, Exception innerException)
-            : base($"Exception has been thrown by the aspect of an invocation. ---> {innerException?.Message}.", innerException)
+            : this(aspectContext, $"Exception has been thrown by the aspect of an invocation. ---> {innerException?.Message}.", innerException) { }
+
+        public AspectInvocationException(AspectContext aspectContext, string message, Exception innerException) : base(message, innerException)
         {
             AspectContext = aspectContext;
         }
diff --git a/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs b/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
deleted file mode 100644
index ec85de6f..00000000
--- a/src/AspectCore.Abstractions/DynamicProxy/IAspectExceptionWrapper.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-
-namespace AspectCore.DynamicProxy
-{
-    public interface IAspectExceptionWrapper
-    {
-        void Wrap(AspectContext aspectContext, Exception exception);
-
-        void ThrowIfFailed();
-    }
-}
\ No newline at end of file
diff --git a/src/AspectCore.Core/DependencyInjection/ServiceContext.cs b/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
index 469e4691..e2e42ae8 100644
--- a/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
+++ b/src/AspectCore.Core/DependencyInjection/ServiceContext.cs
@@ -1,10 +1,10 @@
-﻿using System;
+﻿using AspectCore.Configuration;
+using AspectCore.DynamicProxy;
+using AspectCore.DynamicProxy.Parameters;
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
-using AspectCore.Configuration;
-using AspectCore.DynamicProxy;
-using AspectCore.DynamicProxy.Parameters;
 
 namespace AspectCore.DependencyInjection
 {
@@ -99,8 +99,6 @@ private void AddInternalServices()
                 Scopeds.AddType<IParameterInterceptorSelector, ParameterInterceptorSelector>();
             if (!Contains(typeof(IAspectCachingProvider)))
                 Singletons.AddType<IAspectCachingProvider, AspectCachingProvider>();
-            if (!Contains(typeof(IAspectExceptionWrapper)))
-                Transients.AddType<IAspectExceptionWrapper, AspectExceptionWrapper>();
         }
 
         public int Count => _collection.Count;
diff --git a/src/AspectCore.Core/DynamicProxy/AspectActivator.cs b/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
index 7a68e551..05c5f474 100644
--- a/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
+++ b/src/AspectCore.Core/DynamicProxy/AspectActivator.cs
@@ -1,5 +1,7 @@
-﻿using AspectCore.Core.Utils;
+﻿using AspectCore.Configuration;
+using AspectCore.Core.Utils;
 using System;
+using System.Runtime.ExceptionServices;
 using System.Threading.Tasks;
 
 namespace AspectCore.DynamicProxy
@@ -9,14 +11,13 @@ internal sealed class AspectActivator : IAspectActivator
     {
         private readonly IAspectContextFactory _aspectContextFactory;
         private readonly IAspectBuilderFactory _aspectBuilderFactory;
-        private readonly IAspectExceptionWrapper _aspectExceptionWrapper;
+        private readonly IAspectConfiguration _aspectConfiguration;
 
-        public AspectActivator(IAspectContextFactory aspectContextFactory, IAspectBuilderFactory aspectBuilderFactory,
-            IAspectExceptionWrapper aspectExceptionWrapper)
+        public AspectActivator(IAspectContextFactory aspectContextFactory, IAspectBuilderFactory aspectBuilderFactory, IAspectConfiguration aspectConfiguration)
         {
             _aspectContextFactory = aspectContextFactory;
             _aspectBuilderFactory = aspectBuilderFactory;
-            _aspectExceptionWrapper = aspectExceptionWrapper;
+            _aspectConfiguration = aspectConfiguration;
         }
 
         public TResult Invoke<TResult>(AspectActivatorContext activatorContext)
@@ -28,8 +29,7 @@ public TResult Invoke<TResult>(AspectActivatorContext activatorContext)
                 var task = aspectBuilder.Build()(context);
                 if (task.IsFaulted)
                 {
-                    _aspectExceptionWrapper.Wrap(context, task.Exception.InnerException);
-                    return default;
+                    ExceptionDispatchInfo.Capture(task.Exception.InnerException).Throw();
                 }
                 if (!task.IsCompleted)
                 {
@@ -42,12 +42,13 @@ public TResult Invoke<TResult>(AspectActivatorContext activatorContext)
             }
             catch (Exception ex)
             {
-                _aspectExceptionWrapper.Wrap(context, ex);
-                return default;
+                if (!_aspectConfiguration.ThrowAspectException || ex is AspectInvocationException _)
+                    throw;
+
+                throw new AspectInvocationException(context, ex);
             }
             finally
             {
-                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
@@ -62,8 +63,7 @@ public async Task<TResult> InvokeTask<TResult>(AspectActivatorContext activatorC
 
                 if (invoke.IsFaulted)
                 {
-                    _aspectExceptionWrapper.Wrap(context, invoke.Exception.InnerException);
-                    return default;
+                    ExceptionDispatchInfo.Capture(invoke.Exception.InnerException).Throw();
                 }
 
                 if (!invoke.IsCompleted)
@@ -80,19 +80,18 @@ public async Task<TResult> InvokeTask<TResult>(AspectActivatorContext activatorC
                     case Task _:
                         return default;
                     default:
-                        _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
-                            $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(Task<TResult>)}'."));
-                        return default;
+                        throw new AspectInvalidCastException(context, $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(Task<TResult>)}'.");
                 }
             }
             catch (Exception ex)
             {
-                _aspectExceptionWrapper.Wrap(context, ex);
-                return default;
+                if (!_aspectConfiguration.ThrowAspectException || ex is AspectInvocationException _) 
+                    throw;
+
+                throw new AspectInvocationException(context, ex);
             }
             finally
             {
-                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
@@ -107,8 +106,7 @@ public async ValueTask<TResult> InvokeValueTask<TResult>(AspectActivatorContext
                 
                 if (invoke.IsFaulted)
                 {
-                    _aspectExceptionWrapper.Wrap(context, invoke.Exception.InnerException);
-                    return default;
+                    ExceptionDispatchInfo.Capture(invoke.Exception.InnerException).Throw();
                 }
                 
                 if (!invoke.IsCompleted)
@@ -125,19 +123,18 @@ public async ValueTask<TResult> InvokeValueTask<TResult>(AspectActivatorContext
                     case ValueTask task:
                         return default;
                     default:
-                        _aspectExceptionWrapper.Wrap(context, new InvalidCastException(
-                            $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(ValueTask<TResult>)}'."));
-                        return default;
+                        throw new AspectInvalidCastException(context, $"Unable to cast object of type '{context.ReturnValue.GetType()}' to type '{typeof(ValueTask<TResult>)}'.");
                 }
             }
             catch (Exception ex)
             {
-                _aspectExceptionWrapper.Wrap(context, ex);
-                return default;
+                if (!_aspectConfiguration.ThrowAspectException || ex is AspectInvocationException _)
+                    throw;
+
+                throw new AspectInvocationException(context, ex);
             }
             finally
             {
-                _aspectExceptionWrapper.ThrowIfFailed();
                 _aspectContextFactory.ReleaseContext(context);
             }
         }
diff --git a/src/AspectCore.Core/DynamicProxy/AspectActivatorFactory.cs b/src/AspectCore.Core/DynamicProxy/AspectActivatorFactory.cs
index 1fba3aa0..c6ab13c9 100644
--- a/src/AspectCore.Core/DynamicProxy/AspectActivatorFactory.cs
+++ b/src/AspectCore.Core/DynamicProxy/AspectActivatorFactory.cs
@@ -1,4 +1,5 @@
-﻿using System;
+﻿using AspectCore.Configuration;
+using System;
 
 namespace AspectCore.DynamicProxy
 {
@@ -7,18 +8,18 @@ public sealed class AspectActivatorFactory : IAspectActivatorFactory
     {
         private readonly IAspectContextFactory _aspectContextFactory;
         private readonly IAspectBuilderFactory _aspectBuilderFactory;
-        private readonly IAspectExceptionWrapper _aspectExceptionWrapper;
+        private readonly IAspectConfiguration _aspectConfiguration;
 
-        public AspectActivatorFactory(IAspectContextFactory aspectContextFactory, IAspectBuilderFactory aspectBuilderFactory, IAspectExceptionWrapper aspectExceptionWrapper)
+        public AspectActivatorFactory(IAspectContextFactory aspectContextFactory, IAspectBuilderFactory aspectBuilderFactory, IAspectConfiguration aspectConfiguration)
         {
             _aspectContextFactory = aspectContextFactory ?? throw new ArgumentNullException(nameof(aspectContextFactory));
             _aspectBuilderFactory = aspectBuilderFactory ?? throw new ArgumentNullException(nameof(aspectBuilderFactory));
-            _aspectExceptionWrapper = aspectExceptionWrapper ?? throw new ArgumentNullException(nameof(aspectExceptionWrapper));
+            _aspectConfiguration = aspectConfiguration ?? throw new ArgumentNullException(nameof(aspectConfiguration));
         }
 
         public IAspectActivator Create()
         {
-            return new AspectActivator(_aspectContextFactory, _aspectBuilderFactory, _aspectExceptionWrapper);
+            return new AspectActivator(_aspectContextFactory, _aspectBuilderFactory, _aspectConfiguration);
         }
     }
 }
\ No newline at end of file
diff --git a/src/AspectCore.Core/DynamicProxy/Extensions/AspectContextRuntimeExtensions.cs b/src/AspectCore.Core/DynamicProxy/Extensions/AspectContextRuntimeExtensions.cs
index 428ebcb0..835b7c8f 100644
--- a/src/AspectCore.Core/DynamicProxy/Extensions/AspectContextRuntimeExtensions.cs
+++ b/src/AspectCore.Core/DynamicProxy/Extensions/AspectContextRuntimeExtensions.cs
@@ -82,7 +82,7 @@ public static Task<object> UnwrapAsyncReturnValue(this AspectContext aspectConte
 
             if (!aspectContext.IsAsync())
             {
-                throw new AspectInvocationException(aspectContext, new InvalidOperationException("This operation only support asynchronous method."));
+                throw new AspectInvalidOperationException(aspectContext, "This operation only support asynchronous method.");
             }
 
             var returnValue = aspectContext.ReturnValue;
diff --git a/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs b/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
index 20954e5f..ab93d86a 100644
--- a/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
+++ b/src/AspectCore.Extensions.Autofac/ContainerBuilderExtensions.cs
@@ -1,18 +1,11 @@
-﻿using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using AspectCore.Configuration;
+﻿using AspectCore.Configuration;
+using AspectCore.DependencyInjection;
 using AspectCore.DynamicProxy;
 using AspectCore.DynamicProxy.Parameters;
-using AspectCore.DependencyInjection;
 using Autofac;
-using Autofac.Core;
-using Autofac.Core.Activators;
-using Autofac.Core.Activators.Delegate;
-using Autofac.Core.Activators.Reflection;
 using Autofac.Core.Resolving.Pipeline;
-using AParameter = Autofac.Core.Parameter;
+using System;
+using System.Linq;
 
 namespace AspectCore.Extensions.Autofac
 {
@@ -58,7 +51,6 @@ public static ContainerBuilder RegisterDynamicProxy(this ContainerBuilder contai
             containerBuilder.RegisterType<AspectBuilderFactory>().As<IAspectBuilderFactory>().SingleInstance();
             containerBuilder.RegisterType<ProxyTypeGenerator>().As<IProxyTypeGenerator>().SingleInstance();
             containerBuilder.RegisterType<AspectCachingProvider>().As<IAspectCachingProvider>().SingleInstance();
-            containerBuilder.RegisterType<AspectExceptionWrapper>().As<IAspectExceptionWrapper>().InstancePerDependency();
 
             //全局注册中间件
             containerBuilder.ComponentRegistryBuilder.Registered += (sender, args) =>
diff --git a/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs b/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
index b79df31e..2765b903 100644
--- a/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
+++ b/src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
@@ -1,11 +1,11 @@
-﻿using System;
-using System.Linq;
-using AspectCore.Configuration;
+﻿using AspectCore.Configuration;
+using AspectCore.DependencyInjection;
 using AspectCore.DynamicProxy;
 using AspectCore.DynamicProxy.Parameters;
-using AspectCore.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection.Extensions;
+using System;
+using System.Linq;
 
 namespace AspectCore.Extensions.DependencyInjection
 {
@@ -59,7 +59,6 @@ internal static IServiceCollection TryAddDynamicProxyServices(this IServiceColle
             services.TryAddSingleton<IAspectBuilderFactory, AspectBuilderFactory>();
             services.TryAddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>();
             services.TryAddSingleton<IAspectCachingProvider, AspectCachingProvider>();
-            services.TryAddTransient<IAspectExceptionWrapper, AspectExceptionWrapper>();
 
             services.AddSingleton<IInterceptorSelector, ConfigureInterceptorSelector>();
             services.AddSingleton<IInterceptorSelector, AttributeInterceptorSelector>();
diff --git a/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs b/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
index 7f40cbe1..69a84704 100644
--- a/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
+++ b/src/AspectCore.Extensions.LightInject/ContainerBuilderExtensions.cs
@@ -1,12 +1,11 @@
-﻿using System;
-using System.Collections.Concurrent;
-using System.Linq;
-using System.Reflection;
-using AspectCore.Configuration;
+﻿using AspectCore.Configuration;
 using AspectCore.DependencyInjection;
 using AspectCore.DynamicProxy;
 using AspectCore.DynamicProxy.Parameters;
 using LightInject;
+using System;
+using System.Linq;
+using System.Reflection;
 using IServiceContainer = LightInject.IServiceContainer;
 
 namespace AspectCore.Extensions.LightInject
@@ -72,8 +71,7 @@ public static IServiceContainer RegisterDynamicProxy(this IServiceContainer cont
                 .AddSingleton<IAspectValidatorBuilder, AspectValidatorBuilder>()
                 .AddSingleton<IAspectBuilderFactory, AspectBuilderFactory>()
                 .AddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>()
-                .AddSingleton<IAspectCachingProvider, AspectCachingProvider>()
-                .AddTransient(typeof(IAspectExceptionWrapper), typeof(AspectExceptionWrapper));
+                .AddSingleton<IAspectCachingProvider, AspectCachingProvider>();
 
             var aspectValidator = new AspectValidatorBuilder(aspectConfig).Build();
             container.Decorate(aspectValidator.CreateDecorator());
diff --git a/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs b/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
index 95d807aa..bcb5bea5 100644
--- a/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
+++ b/src/AspectCore.Extensions.Windsor/AspectCoreFacility.cs
@@ -1,13 +1,13 @@
-﻿using System;
-using System.Linq;
-using AspectCore.Configuration;
+﻿using AspectCore.Configuration;
+using AspectCore.DependencyInjection;
 using AspectCore.DynamicProxy;
 using AspectCore.DynamicProxy.Parameters;
-using AspectCore.DependencyInjection;
 using Castle.Core;
 using Castle.Core.Configuration;
 using Castle.MicroKernel;
 using Castle.MicroKernel.Registration;
+using System;
+using System.Linq;
 
 namespace AspectCore.Extensions.Windsor
 {
@@ -36,7 +36,6 @@ public void Init(IKernel kernel, IConfiguration facilityConfig)
                 Component.For<IInterceptorCollector>().ImplementedBy<InterceptorCollector>().LifestyleSingleton(),
                 Component.For<IAspectContextFactory>().ImplementedBy<AspectContextFactory>().LifestyleSingleton(),
                 Component.For<IAspectCachingProvider>().ImplementedBy<AspectCachingProvider>().LifestyleSingleton(),
-                Component.For<IAspectExceptionWrapper>().ImplementedBy<AspectExceptionWrapper>().LifestyleTransient(),
                 Component.For<IAspectActivatorFactory>().ImplementedBy<AspectActivatorFactory>().LifestyleSingleton(),
                 Component.For<IAspectValidatorBuilder>().ImplementedBy<AspectValidatorBuilder>().LifestyleSingleton(),
                 Component.For<IPropertyInjectorFactory>().ImplementedBy<PropertyInjectorFactory>().LifestyleSingleton(),
diff --git a/src/AspectCore.Extensions.Windsor/DynamicProxyInterceptor.cs b/src/AspectCore.Extensions.Windsor/DynamicProxyInterceptor.cs
index 4890f2be..e23ae561 100644
--- a/src/AspectCore.Extensions.Windsor/DynamicProxyInterceptor.cs
+++ b/src/AspectCore.Extensions.Windsor/DynamicProxyInterceptor.cs
@@ -1,10 +1,10 @@
-﻿using System;
-using System.Reflection;
-using System.Threading;
-using System.Threading.Tasks;
+﻿using AspectCore.Configuration;
 using AspectCore.DynamicProxy;
 using AspectCore.Extensions.Reflection;
 using Castle.DynamicProxy;
+using System;
+using System.Reflection;
+using System.Threading.Tasks;
 using CastleIntercrptor = Castle.DynamicProxy.IInterceptor;
 
 namespace AspectCore.Extensions.Windsor
@@ -15,7 +15,7 @@ public class DynamicProxyInterceptor : CastleIntercrptor
         private readonly IAspectBuilderFactory _aspectBuilderFactory;
         private readonly IAspectContextFactory _aspectContextFactory;
         private readonly IAspectValidator _aspectValidator;
-        private readonly IAspectExceptionWrapper _aspectExceptionWrapper;
+        private readonly IAspectConfiguration _aspectConfiguration;
         private const string IndexFieldName = "currentInterceptorIndex";
 
         private static readonly FieldInfo _indexFieldInfo = typeof(AbstractInvocation).GetField(IndexFieldName,
@@ -23,12 +23,12 @@ public class DynamicProxyInterceptor : CastleIntercrptor
 
         public DynamicProxyInterceptor(IAspectBuilderFactory aspectBuilderFactory,
             IAspectContextFactory aspectContextFactory, IAspectValidatorBuilder aspectValidatorBuilder,
-            IAspectExceptionWrapper aspectExceptionWrapper)
+            IAspectConfiguration aspectConfiguration)
         {
             _aspectBuilderFactory = aspectBuilderFactory ?? throw new ArgumentNullException(nameof(aspectBuilderFactory));
             _aspectContextFactory = aspectContextFactory ?? throw new ArgumentNullException(nameof(aspectContextFactory));
             _aspectValidator = aspectValidatorBuilder?.Build() ?? throw new ArgumentNullException(nameof(aspectValidatorBuilder));
-            _aspectExceptionWrapper = aspectExceptionWrapper ?? throw new ArgumentNullException(nameof(aspectExceptionWrapper));
+            _aspectConfiguration = aspectConfiguration ?? throw new ArgumentNullException(nameof(aspectConfiguration));
         }
 
         public void Intercept(IInvocation invocation)
@@ -54,7 +54,7 @@ public void Intercept(IInvocation invocation)
                 return Task.FromResult(0);
             });
             var proxyMethod = proxyTypeInfo.GetMethodBySignature(invocation.Method);
-            var activator = new AspectActivatorFactory(_aspectContextFactory, builderFactory, _aspectExceptionWrapper).Create();
+            var activator = new AspectActivatorFactory(_aspectContextFactory, builderFactory, _aspectConfiguration).Create();
             var activatorContext = new AspectActivatorContext(invocation.Method, invocation.MethodInvocationTarget, proxyMethod, invocation.InvocationTarget, invocation.Proxy,
                 invocation.Arguments);
             var reflector = InterceptUtils.GetInvokeReflector(invocation.Method);
diff --git a/tests/AspectCore.Tests/DynamicProxy/ThrowExceptionDirectlyTests.cs b/tests/AspectCore.Tests/DynamicProxy/ThrowExceptionDirectlyTests.cs
new file mode 100644
index 00000000..dbb0cbbe
--- /dev/null
+++ b/tests/AspectCore.Tests/DynamicProxy/ThrowExceptionDirectlyTests.cs
@@ -0,0 +1,154 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using AspectCore.Configuration;
+using AspectCore.DynamicProxy;
+using Xunit;
+
+namespace AspectCore.Tests.DynamicProxy
+{
+    public class ThrowExceptionDirectlyTester
+    {
+        [Nothing]
+        public virtual int ThrowOfResult() => throw new ArgumentException();
+        [Nothing]
+        public virtual Task<int> ThrowAsyncOfTaskResult() => throw new ArgumentException();
+        [Nothing]
+        public virtual ValueTask<int> ThrowAsyncOfValueTask() => throw new ArgumentException();
+
+        [Nothing]
+        public virtual Task ThrowInMainTask()
+        {
+            return Task.Run(() => throw new ArgumentException())
+                .ContinueWith(m =>
+                {
+                    if (m.IsFaulted)
+                        throw m.Exception.InnerException;
+                });
+        }
+
+        [Nothing]
+        public virtual Task ThrowInUncontinuedTasks()
+        {
+            return Task.Run(() => throw new ArgumentException())
+                .ContinueWith(m => Console.WriteLine(m.Status), TaskContinuationOptions.OnlyOnRanToCompletion);
+        }
+        
+        [Nothing]
+        public virtual Task ThrowInSubTask()
+        {
+            return Task.Run(() => Task.FromResult(1))
+                .ContinueWith(m => throw new ArgumentException());
+        }
+    }
+
+    public class ThrowExceptionDirectlyTests : DynamicProxyTestBase
+    {
+        private static void AssertSameThrows(Func<object> action, Func<object> proxyAction)
+        {
+            try
+            {
+                action();
+            }
+            catch (Exception ex)
+            {
+                try
+                {
+                    proxyAction();
+                }
+                catch (Exception exOfProxy)
+                {
+                    Assert.Equal(ex.GetType(), exOfProxy.GetType());
+                    return;
+                }
+                throw new InvalidOperationException("no exception in proxyAction");
+            }
+            throw new InvalidOperationException("no exception in action");
+        }
+
+        private static async Task AssertSameThrowsAsync(Func<Task> action, Func<Task> proxyAction)
+        {
+            try
+            {
+                await action();
+            }
+            catch (Exception ex)
+            {
+                try
+                {
+                    await proxyAction();
+                }
+                catch (Exception exOfProxy)
+                {
+                    Assert.Equal(ex.GetType(), exOfProxy.GetType());
+                    return;
+                }
+                throw new InvalidOperationException("no exception in proxyAction");
+            }
+            throw new InvalidOperationException("no exception in action");
+        }
+
+        [Fact]
+        public async Task TestThrowException()
+        {
+            var obj = new ThrowExceptionDirectlyTester();
+            var proxy = ProxyGenerator.CreateClassProxy<ThrowExceptionDirectlyTester>();
+            Assert.True(proxy.IsProxy());
+
+            AssertSameThrows(
+                () => obj.ThrowOfResult(),
+                () => proxy.ThrowOfResult());
+
+            await AssertSameThrowsAsync(
+                async () => await obj.ThrowAsyncOfTaskResult(),
+                async () => await proxy.ThrowAsyncOfTaskResult());
+
+            await AssertSameThrowsAsync(
+                async () => await obj.ThrowAsyncOfValueTask(),
+                async () => await proxy.ThrowAsyncOfValueTask());
+        }
+
+        [Fact]
+        public async Task TestThrowInMainTask()
+        {
+            var obj = new ThrowExceptionDirectlyTester();
+            var proxy = ProxyGenerator.CreateClassProxy<ThrowExceptionDirectlyTester>();
+            Assert.True(proxy.IsProxy());
+
+            await AssertSameThrowsAsync(
+                async () => await obj.ThrowInMainTask(),
+                async () => await proxy.ThrowInMainTask());
+        }
+
+        [Fact]
+        public async Task TestThrowInSubTask()
+        {
+            var obj = new ThrowExceptionDirectlyTester();
+            var proxy = ProxyGenerator.CreateClassProxy<ThrowExceptionDirectlyTester>();
+            Assert.True(proxy.IsProxy());
+
+            await AssertSameThrowsAsync(
+                async () => await obj.ThrowInSubTask(),
+                async () => await proxy.ThrowInSubTask());
+        }
+
+        [Fact]
+        public async Task TestThrowInUncontinuedTasks()
+        {
+            var obj = new ThrowExceptionDirectlyTester();
+            var proxy = ProxyGenerator.CreateClassProxy<ThrowExceptionDirectlyTester>();
+            Assert.True(proxy.IsProxy());
+
+            // todo re-test
+            // await AssertSameThrowsAsync(
+            //     async () => await obj.ThrowInUncontinuedTasks(),
+            //     async () => await proxy.ThrowInUncontinuedTasks());
+        }
+
+        protected override void Configure(IAspectConfiguration configuration)
+        {
+            base.Configure(configuration);
+        }
+    }
+}

From b1a06b50439b6bdcea3839e5fc007ca433e84b59 Mon Sep 17 00:00:00 2001
From: NivalXer <nivalxer@users.noreply.github.com>
Date: Wed, 24 May 2023 15:55:05 +0800
Subject: [PATCH 6/8] =?UTF-8?q?=E8=B0=83=E6=95=B4TargetFrameworks=20(#310)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Change some TargetFrameworks

* 兼容.net老版本的系统包

---------

Co-authored-by: Liu Haoyang <liuhaoyang1221@hotmail.com>
---
 .../AspectCore.Abstractions.csproj            |  2 +-
 src/AspectCore.Core/AspectCore.Core.csproj    |  2 +-
 .../AspectCore.Extensions.AspNetCore.csproj   |  4 +--
 .../AspectCore.Extensions.AspectScope.csproj  |  2 +-
 .../AspectCore.Extensions.Autofac.csproj      |  2 +-
 ...AspectCore.Extensions.Configuration.csproj | 32 +++++++------------
 ...pectCore.Extensions.DataAnnotations.csproj |  2 +-
 ...spectCore.Extensions.DataValidation.csproj |  2 +-
 ...Core.Extensions.DependencyInjection.csproj | 15 ++-------
 .../AspectCore.Extensions.Hosting.csproj      | 11 ++-----
 .../AspectCore.Extensions.LightInject.csproj  |  2 +-
 .../AspectCore.Extensions.Reflection.csproj   |  2 +-
 12 files changed, 27 insertions(+), 51 deletions(-)

diff --git a/src/AspectCore.Abstractions/AspectCore.Abstractions.csproj b/src/AspectCore.Abstractions/AspectCore.Abstractions.csproj
index bfd215b6..27df1ac2 100644
--- a/src/AspectCore.Abstractions/AspectCore.Abstractions.csproj
+++ b/src/AspectCore.Abstractions/AspectCore.Abstractions.csproj
@@ -9,7 +9,7 @@
     <PackageId>AspectCore.Abstractions</PackageId>
     <PackageTags>DynamicProxy;Aop;Aspect;AspectCore;Interceptor</PackageTags>
     <PackageReleaseNotes>The abstract design of the AspectCore framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Core/AspectCore.Core.csproj b/src/AspectCore.Core/AspectCore.Core.csproj
index aa047b41..5d827b1f 100644
--- a/src/AspectCore.Core/AspectCore.Core.csproj
+++ b/src/AspectCore.Core/AspectCore.Core.csproj
@@ -8,7 +8,7 @@
     <PackageId>AspectCore.Core</PackageId>
     <PackageTags>DynamicProxy;Aop;Aspect;AspectCore;Interceptor</PackageTags>
     <PackageReleaseNotes>The implementation of the AspectCore framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.AspNetCore/AspectCore.Extensions.AspNetCore.csproj b/src/AspectCore.Extensions.AspNetCore/AspectCore.Extensions.AspNetCore.csproj
index 21cd36c5..961a58eb 100644
--- a/src/AspectCore.Extensions.AspNetCore/AspectCore.Extensions.AspNetCore.csproj
+++ b/src/AspectCore.Extensions.AspNetCore/AspectCore.Extensions.AspNetCore.csproj
@@ -10,8 +10,8 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <FrameworkReference Include="Microsoft.AspNetCore.App" />
-    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
+	  <FrameworkReference Include="Microsoft.AspNetCore.App" />
+	  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
   </ItemGroup>
 
   <ItemGroup>
diff --git a/src/AspectCore.Extensions.AspectScope/AspectCore.Extensions.AspectScope.csproj b/src/AspectCore.Extensions.AspectScope/AspectCore.Extensions.AspectScope.csproj
index a4076903..e85943cd 100644
--- a/src/AspectCore.Extensions.AspectScope/AspectCore.Extensions.AspectScope.csproj
+++ b/src/AspectCore.Extensions.AspectScope/AspectCore.Extensions.AspectScope.csproj
@@ -10,7 +10,7 @@
     <Title>AspectCore.Extensions.AspectScope</Title>
     <PackageTags>DynamicProxy;Aop;Aspect;AspectCore;Intercepter</PackageTags>
     <PackageReleaseNotes>ScopedContext extension system for AspectCore Framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj b/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
index 51ec3780..1720b734 100644
--- a/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
+++ b/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
@@ -9,7 +9,7 @@
     <PackageId>AspectCore.Extensions.Autofac</PackageId>
     <PackageTags>DynamicProxy;Aop;Autofac;AspectCore</PackageTags>
     <PackageReleaseNotes>Interceptor and dynamicProxy support for Autofac via AspectCore Framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.Configuration/AspectCore.Extensions.Configuration.csproj b/src/AspectCore.Extensions.Configuration/AspectCore.Extensions.Configuration.csproj
index 72b1603e..f26da9b4 100644
--- a/src/AspectCore.Extensions.Configuration/AspectCore.Extensions.Configuration.csproj
+++ b/src/AspectCore.Extensions.Configuration/AspectCore.Extensions.Configuration.csproj
@@ -8,33 +8,14 @@
 		<PackageId>AspectCore.Extensions.Configuration</PackageId>
 		<PackageTags>Reflection;Aop;DynamicProxy;Configuration</PackageTags>
 		<PackageReleaseNotes>Configuration extension system for ASP.NET Core via AspectCore-Framework.</PackageReleaseNotes>
-		<TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.0</TargetFrameworks>
+		<TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
 
 		<PublishRepositoryUrl>true</PublishRepositoryUrl>
 		<IncludeSymbols>true</IncludeSymbols>
 		<SymbolPackageFormat>snupkg</SymbolPackageFormat>
 	</PropertyGroup>
 
-	<ItemGroup>
-		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
-	</ItemGroup>
-
-	<ItemGroup>
-		<ProjectReference Include="..\AspectCore.Abstractions\AspectCore.Abstractions.csproj" />
-		<ProjectReference Include="..\AspectCore.Extensions.Reflection\AspectCore.Extensions.Reflection.csproj" />
-	</ItemGroup>
-
-	<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
-		<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.0" />
-		<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
-	</ItemGroup>
-
-	<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
-		<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
-		<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.0" />
-	</ItemGroup>
-
-	<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
+	<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
 		<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
 		<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
 	</ItemGroup>
@@ -49,4 +30,13 @@
 		<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
 	</ItemGroup>
 
+	<ItemGroup>
+		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
+	</ItemGroup>
+
+	<ItemGroup>
+		<ProjectReference Include="..\AspectCore.Abstractions\AspectCore.Abstractions.csproj" />
+		<ProjectReference Include="..\AspectCore.Extensions.Reflection\AspectCore.Extensions.Reflection.csproj" />
+	</ItemGroup>
+
 </Project>
\ No newline at end of file
diff --git a/src/AspectCore.Extensions.DataAnnotations/AspectCore.Extensions.DataAnnotations.csproj b/src/AspectCore.Extensions.DataAnnotations/AspectCore.Extensions.DataAnnotations.csproj
index 4e83c4be..4c365734 100644
--- a/src/AspectCore.Extensions.DataAnnotations/AspectCore.Extensions.DataAnnotations.csproj
+++ b/src/AspectCore.Extensions.DataAnnotations/AspectCore.Extensions.DataAnnotations.csproj
@@ -9,7 +9,7 @@
     <PackageId>AspectCore.Extensions.DataAnnotations</PackageId>
     <PackageTags>DataValidation;DataAnnotations;AspectCore;AOP</PackageTags>
     <PackageReleaseNotes>DataAnnotations extension system for AspectCore Framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.DataValidation/AspectCore.Extensions.DataValidation.csproj b/src/AspectCore.Extensions.DataValidation/AspectCore.Extensions.DataValidation.csproj
index 31ce0695..d9de4267 100644
--- a/src/AspectCore.Extensions.DataValidation/AspectCore.Extensions.DataValidation.csproj
+++ b/src/AspectCore.Extensions.DataValidation/AspectCore.Extensions.DataValidation.csproj
@@ -9,7 +9,7 @@
     <PackageId>AspectCore.Extensions.DataValidation</PackageId>
     <PackageTags>DataValidation;AspectCore;AOP</PackageTags>
     <PackageReleaseNotes>DataValidation extension system for AspectCore Framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.DependencyInjection/AspectCore.Extensions.DependencyInjection.csproj b/src/AspectCore.Extensions.DependencyInjection/AspectCore.Extensions.DependencyInjection.csproj
index 01b4b389..c9728f0b 100644
--- a/src/AspectCore.Extensions.DependencyInjection/AspectCore.Extensions.DependencyInjection.csproj
+++ b/src/AspectCore.Extensions.DependencyInjection/AspectCore.Extensions.DependencyInjection.csproj
@@ -10,7 +10,7 @@
     <PackageTags>DynamicProxy;Aop;DependencyInjection;AspectCore</PackageTags>
     <PackageReleaseNotes>Interceptor and dynamicProxy support for Microsoft.Extensions.DependencyInjection via AspectCore Framework.</PackageReleaseNotes>
     <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.0</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
@@ -20,17 +20,8 @@
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
   </ItemGroup>
 
-
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
-    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
-  </ItemGroup>
-
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
-    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
-  </ItemGroup>
-
-  <ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
-    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
+  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
+	  <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
   </ItemGroup>
 
   <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
diff --git a/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj b/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj
index 394cd72f..301f6c8a 100644
--- a/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj
+++ b/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj
@@ -1,7 +1,7 @@
 ﻿<Project Sdk="Microsoft.NET.Sdk">
   <Import Project="..\..\build\common.props" />
   <PropertyGroup>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
@@ -11,13 +11,8 @@
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
   </ItemGroup>
 
-
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
-    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
-  </ItemGroup>
-
-  <ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
-    <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
+  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
+	  <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
   </ItemGroup>
 
   <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
diff --git a/src/AspectCore.Extensions.LightInject/AspectCore.Extensions.LightInject.csproj b/src/AspectCore.Extensions.LightInject/AspectCore.Extensions.LightInject.csproj
index 59c52146..84b73f7e 100644
--- a/src/AspectCore.Extensions.LightInject/AspectCore.Extensions.LightInject.csproj
+++ b/src/AspectCore.Extensions.LightInject/AspectCore.Extensions.LightInject.csproj
@@ -7,7 +7,7 @@
     <PackageTags>DynamicProxy;Aop;LightInject;AspectCore</PackageTags>
     <PackageReleaseNotes>Interceptor and dynamicProxy support for LightInject via AspectCore Framework.</PackageReleaseNotes>
     <GeneratePackageOnBuild>false</GeneratePackageOnBuild>	
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
diff --git a/src/AspectCore.Extensions.Reflection/AspectCore.Extensions.Reflection.csproj b/src/AspectCore.Extensions.Reflection/AspectCore.Extensions.Reflection.csproj
index 558acdd9..145f3de8 100644
--- a/src/AspectCore.Extensions.Reflection/AspectCore.Extensions.Reflection.csproj
+++ b/src/AspectCore.Extensions.Reflection/AspectCore.Extensions.Reflection.csproj
@@ -8,7 +8,7 @@
     <PackageId>AspectCore.Extensions.Reflection</PackageId>
     <PackageTags>Reflection;Aop;DynamicProxy</PackageTags>
     <PackageReleaseNotes>Reflection extension system for AspectCore Framework.</PackageReleaseNotes>
-    <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
+    <TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>

From da2e2c20a9af4001eb2f682a4f9ea6215f397dab Mon Sep 17 00:00:00 2001
From: NivalXer <nivalxer@users.noreply.github.com>
Date: Thu, 25 May 2023 11:25:55 +0800
Subject: [PATCH 7/8] bump autofac to 7.0.0 and fix build error (#309)

* bump autofac to 7.0.0 and fix build error

* limit autofac version

---------

Co-authored-by: Liu Haoyang <liuhaoyang1221@hotmail.com>
---
 .../ActivationResolveMiddleware.cs                              | 2 +-
 .../AspectCore.Extensions.Autofac.csproj                        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/AspectCore.Extensions.Autofac/ActivationResolveMiddleware.cs b/src/AspectCore.Extensions.Autofac/ActivationResolveMiddleware.cs
index ba2f21f3..494ff321 100644
--- a/src/AspectCore.Extensions.Autofac/ActivationResolveMiddleware.cs
+++ b/src/AspectCore.Extensions.Autofac/ActivationResolveMiddleware.cs
@@ -92,7 +92,7 @@ public void Execute(ResolveRequestContext context, Action<ResolveRequestContext>
 
                 if (availableConstructors.Length == 0)
                 {
-                    throw new NoConstructorsFoundException(proxyType, $"No constructors on type '{proxyType}' can be found with the constructor finder '{constructorFinder}'.");
+                    throw new NoConstructorsFoundException(proxyType, constructorFinder);
                 }
 
                 var binders = new ConstructorBinder[availableConstructors.Length];
diff --git a/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj b/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
index 1720b734..741898f3 100644
--- a/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
+++ b/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj
@@ -21,7 +21,7 @@
 
 
   <ItemGroup>
-    <PackageReference Include="Autofac" Version="6.4.0" />
+    <PackageReference Include="Autofac" Version="[7.0.0, 8.0.0)" />
   </ItemGroup>
 
   <ItemGroup>

From dfd5cf6adf2322141f45a59a4b7d7e2202a52c08 Mon Sep 17 00:00:00 2001
From: Liu Haoyang <liuhaoyang1221@hotmail.com>
Date: Thu, 25 May 2023 16:40:04 +0800
Subject: [PATCH 8/8] Update version.props (#311)

---
 build/version.props | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build/version.props b/build/version.props
index 5f50de5e..91c600cc 100644
--- a/build/version.props
+++ b/build/version.props
@@ -1,7 +1,7 @@
 <Project>
 	<PropertyGroup>
 		<VersionMajor>2</VersionMajor>
-		<VersionMinor>3</VersionMinor>
+		<VersionMinor>4</VersionMinor>
 		<VersionPatch>0</VersionPatch>
 		<VersionQuality></VersionQuality>
 		<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
