From 10f6ad0c6416ee7b84427b30a3068fec2005e6aa Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Wed, 24 Mar 2021 16:18:02 -0700 Subject: [PATCH 1/2] Change the accessbility to virtual for Resource.Id --- .../Azure.ResourceManager.Core/src/Resources/Resource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs index 86a35ac05cf77..a8638d1c689be 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs @@ -14,7 +14,7 @@ public abstract class Resource : IEquatable, IEquatable, IComp /// /// Gets or sets the resource identifier. /// - public abstract ResourceIdentifier Id { get; protected set; } + public virtual ResourceIdentifier Id { get; protected set; } /// /// Gets the name. From 1b60da99c0b91ebe867b554773a5d65bf780080a Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Fri, 25 Jun 2021 12:34:22 -0700 Subject: [PATCH 2/2] Catch TargetInvocationException in interceptor --- .../Instrumentation/ManagementInterceptor.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sdk/core/Azure.Core.TestFramework/src/Instrumentation/ManagementInterceptor.cs b/sdk/core/Azure.Core.TestFramework/src/Instrumentation/ManagementInterceptor.cs index 53bd2a9308e1c..dbc193e9ddfdf 100644 --- a/sdk/core/Azure.Core.TestFramework/src/Instrumentation/ManagementInterceptor.cs +++ b/sdk/core/Azure.Core.TestFramework/src/Instrumentation/ManagementInterceptor.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Linq; using System.Reflection; using System.Threading.Tasks; using Castle.DynamicProxy; @@ -39,11 +40,25 @@ public void Intercept(IInvocation invocation) var taskResultType = type.GetGenericArguments()[0]; if (taskResultType.Name.StartsWith("Response")) { - var taskResult = result.GetType().GetProperty("Result").GetValue(result); - var instrumentedResult = _testBase.InstrumentClient(taskResultType, taskResult, new IInterceptor[] { new ManagementInterceptor(_testBase) }); - invocation.ReturnValue = type.Name.StartsWith("ValueTask") - ? GetValueFromValueTask(taskResultType, instrumentedResult) - : GetValueFromOther(taskResultType, instrumentedResult); + try + { + var taskResult = result.GetType().GetProperty("Result").GetValue(result); + var instrumentedResult = _testBase.InstrumentClient(taskResultType, taskResult, new IInterceptor[] { new ManagementInterceptor(_testBase) }); + invocation.ReturnValue = type.Name.StartsWith("ValueTask") + ? GetValueFromValueTask(taskResultType, instrumentedResult) + : GetValueFromOther(taskResultType, instrumentedResult); + } + catch (TargetInvocationException e) + { + if (e.InnerException is AggregateException aggException) + { + throw aggException.InnerExceptions.First(); + } + else + { + throw e.InnerException; + } + } } } else if (invocation.Method.Name.EndsWith("Value") && type.BaseType.Name.EndsWith("Operations"))