Auto-Instrumentation - Enable AI SDK to honor repacked Azure.Identity assembly name (#2406)
* Redfield AAD change. * Test changes * PR Feedback * azureCoreAssemblyName lowercase
This commit is contained in:
Родитель
d54bae8aea
Коммит
b6483cd488
|
@ -1,4 +1,4 @@
|
|||
#if !NET452 && !NET46
|
||||
#if !NET452 && !NET46 && !REDFIELD
|
||||
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
|
||||
{
|
||||
using System;
|
||||
|
@ -302,7 +302,7 @@ namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementati
|
|||
var test = compiledExpression2.DynamicInvoke(objAccessToken);
|
||||
|
||||
}
|
||||
#region TestClasses
|
||||
#region TestClasses
|
||||
|
||||
/// <summary>
|
||||
/// This class inherits <see cref="MockCredential"/> which inherits <see cref="Azure.Core.TokenCredential"/>.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#if !NET452 && !NET46
|
||||
#if !NET452 && !NET46 && !REDFIELD
|
||||
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
|
||||
{
|
||||
using System;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#if !NET452 && !NET46
|
||||
#if !NET452 && !NET46 && !REDFIELD
|
||||
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
|
||||
{
|
||||
using System;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#if !NET452 && !NET46
|
||||
#if !NET452 && !NET46 && !REDFIELD
|
||||
namespace Microsoft.ApplicationInsights.TestFramework.Implementation
|
||||
{
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
/// </remarks>
|
||||
internal class ReflectionCredentialEnvelope : CredentialEnvelope
|
||||
{
|
||||
#if REDFIELD
|
||||
private static volatile string azureCoreAssemblyName = "Azure.Identity.ILRepack";
|
||||
#else
|
||||
private static volatile string azureCoreAssemblyName = "Azure.Core";
|
||||
#endif
|
||||
|
||||
private readonly object tokenCredential;
|
||||
private readonly object tokenRequestContext;
|
||||
|
||||
|
@ -102,8 +108,7 @@
|
|||
/// </returns>
|
||||
private static Type GetTokenCredentialType()
|
||||
{
|
||||
var typeName = "Azure.Core.TokenCredential, Azure.Core";
|
||||
var assemblyName = "Azure.Core";
|
||||
var typeName = $"Azure.Core.TokenCredential, {azureCoreAssemblyName}";
|
||||
|
||||
Type typeTokenCredential = null;
|
||||
|
||||
|
@ -118,7 +123,7 @@
|
|||
|
||||
if (typeTokenCredential == null)
|
||||
{
|
||||
if (AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.StartsWith(assemblyName)))
|
||||
if (AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.StartsWith(azureCoreAssemblyName)))
|
||||
{
|
||||
throw new Exception("An unknown error has occurred. Failed to get type Azure.Core.TokenCredential. Detected that Azure.Core is loaded in AppDomain.CurrentDomain.");
|
||||
}
|
||||
|
@ -169,7 +174,7 @@
|
|||
internal static object MakeTokenRequestContext(string[] scopes)
|
||||
{
|
||||
return Activator.CreateInstance(
|
||||
type: Type.GetType("Azure.Core.TokenRequestContext, Azure.Core"),
|
||||
type: Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}"),
|
||||
args: new object[] { scopes, null, });
|
||||
}
|
||||
|
||||
|
@ -183,7 +188,7 @@
|
|||
/// </returns>
|
||||
private static Delegate BuildDelegateAccessTokenToAuthToken()
|
||||
{
|
||||
Type typeAccessToken = Type.GetType("Azure.Core.AccessToken, Azure.Core");
|
||||
Type typeAccessToken = Type.GetType($"Azure.Core.AccessToken, {azureCoreAssemblyName}");
|
||||
|
||||
var parameterExpression_AccessToken = Expression.Parameter(typeAccessToken, "parameterExpression_AccessToken");
|
||||
|
||||
|
@ -218,8 +223,8 @@
|
|||
/// </returns>
|
||||
private static Delegate BuildDelegateGetToken()
|
||||
{
|
||||
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
|
||||
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
|
||||
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
|
||||
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
|
||||
Type typeCancellationToken = typeof(CancellationToken);
|
||||
|
||||
var parameterExpression_tokenCredential = Expression.Parameter(type: typeTokenCredential, name: "parameterExpression_TokenCredential");
|
||||
|
@ -255,8 +260,8 @@
|
|||
/// </returns>
|
||||
private static Delegate BuildDelegateGetTokenAsync()
|
||||
{
|
||||
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
|
||||
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
|
||||
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
|
||||
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
|
||||
Type typeCancellationToken = typeof(CancellationToken);
|
||||
|
||||
var parameterExpression_TokenCredential = Expression.Parameter(type: typeTokenCredential, name: "parameterExpression_TokenCredential");
|
||||
|
@ -297,8 +302,8 @@
|
|||
/// </returns>
|
||||
private static Delegate BuildGetTaskResult()
|
||||
{
|
||||
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
|
||||
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
|
||||
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
|
||||
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
|
||||
Type typeCancellationToken = typeof(CancellationToken);
|
||||
var methodInfo_GetTokenAsync = typeTokenCredential.GetMethod(name: "GetTokenAsync", types: new Type[] { typeTokenRequestContext, typeCancellationToken });
|
||||
var methodInfo_AsTask = methodInfo_GetTokenAsync.ReturnType.GetMethod("AsTask");
|
||||
|
|
Загрузка…
Ссылка в новой задаче