Skip to content

Commit 3eed9f6

Browse files
authored
[Azure.Identity] Change DAC to use reflection behavior analyzable by ILLinker (Azure#49427)
* attempt fix * fix GetType syntax * trying something * undo packages fixes and fix ci * forgot to add the filepath to ci.yml
1 parent 0dacd62 commit 3eed9f6

File tree

5 files changed

+12
-21
lines changed

5 files changed

+12
-21
lines changed

eng/scripts/compatibility/Check-AOT-Compatibility.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ $actualWarningCount = 0
8080

8181
foreach ($line in $($publishOutput -split "`r`n"))
8282
{
83-
if ($line -like "*analysis warning IL*")
83+
if ($line -like "*warning IL*")
8484
{
8585
$actualWarningCount += 1
8686
}

sdk/identity/Azure.Identity.Broker/src/DevelopmentBrokerOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Azure.Identity.Broker
1212
/// Options to configure the <see cref="InteractiveBrowserCredential"/> to use the system authentication broker in lieu of an embedded web view or the system browser.
1313
/// For more information, see <see href="https://aka.ms/azsdk/net/identity/interactive-brokered-auth">Interactive brokered authentication</see>.
1414
/// </summary>
15-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
1615
internal class DevelopmentBrokerOptions : InteractiveBrowserCredentialOptions, IMsalSettablePublicClientInitializerOptions, IMsalPublicClientInitializerOptions
1716
{
1817
private Action<PublicClientApplicationBuilder> _beforeBuildClient;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ILC : warning IL3000: Microsoft\.Identity\.Client\.NativeInterop\.Platform\.GetExecutingAssemblyDirectory\(\): 'System\.Reflection\.Assembly\.Location\.get' always returns an empty string for assemblies embedded in a single-file app\. If the path to the app directory is needed, consider calling 'System\.AppContext\.BaseDirectory'

sdk/identity/Azure.Identity/src/DefaultAzureCredentialFactory.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,19 @@ public virtual TokenCredential CreateAzurePowerShellCredential()
262262
/// This is used to enable broker authentication for development purposes.
263263
/// </summary>
264264
/// <param name="options"></param>
265-
/// <returns></returns>
266-
[UnconditionalSuppressMessage("Trimming", "IL2026",
267-
Justification = "Assembly.Load is used for optional functionality. If the assembly is trimmed, the catch block handles it gracefully.")]
268-
[UnconditionalSuppressMessage("Trimming", "IL2072",
269-
Justification = "Loading Azure.Identity.Broker assembly is optional, method handles missing assembly gracefully")]
270265
internal static bool TryCreateDevelopmentBrokerOptions(out InteractiveBrowserCredentialOptions options)
271266
{
272267
options = null;
273268
try
274269
{
275-
// Check if the Azure.Identity.Broker assembly is loaded
276-
Assembly brokerAssembly;
277-
brokerAssembly = Assembly.Load("Azure.Identity.Broker");
278-
279-
if (brokerAssembly != null)
280-
{
281-
// Get the DevelopmentBrokerOptions type
282-
var optionsType = brokerAssembly.GetType("Azure.Identity.Broker.DevelopmentBrokerOptions");
283-
if (optionsType != null)
284-
{
285-
// Create an instance using the parameterless constructor
286-
options = (InteractiveBrowserCredentialOptions)Activator.CreateInstance(optionsType);
287-
}
288-
}
270+
// Use Type.GetType and ConstructorInfo because they can be analyzed by the ILLinker and are
271+
// AOT friendly.
272+
273+
// Try to get the options type
274+
Type optionsType = Type.GetType("Azure.Identity.Broker.DevelopmentBrokerOptions, Azure.Identity.Broker", throwOnError: false);
275+
ConstructorInfo optionsCtor = optionsType?.GetConstructor(Type.EmptyTypes);
276+
object optionsInstance = optionsCtor?.Invoke(null);
277+
options = optionsInstance as InteractiveBrowserCredentialOptions;
289278

290279
return options != null;
291280
}

sdk/identity/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ extends:
3535
AOTTestInputs:
3636
- ArtifactName: Azure.Identity
3737
ExpectedWarningsFilepath: None
38+
- ArtifactName: Azure.Identity.Broker
39+
ExpectedWarningsFilepath: "Azure.Identity.Broker/tests/compatibility/ExpectedWarnings.txt"

0 commit comments

Comments
 (0)