Skip to content

[Bug] MSAL.Net RuntimeBroker doesn't support NativeAOT on windows. #4424

@azchohfi

Description

@azchohfi

Library version used

4.57.0

.NET version

8.0

Scenario

PublicClient - desktop app

Is this a new or an existing app?

None

Issue description and reproduction steps

Calling await _app.GetAccountsAsync() with nativeaot turned on throws an exception.

Relevant code snippets

Unhandled exception: MSAL.NetCore.4.57.0.0.MsalClientException:
        ErrorCode: wam_runtime_init_failed
Microsoft.Identity.Client.MsalClientException: A type initializer threw an exception.
 ---> System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
   at System.Reflection.Runtime.Assemblies.RuntimeAssemblyInfo.get_CodeBase()
   at Microsoft.Identity.Client.NativeInterop.Platform.GetExecutingAssemblyDirectory()
   at Microsoft.Identity.Client.NativeInterop.API.GetPackagePathAndSetEnvironmentVariables()
   at Microsoft.Identity.Client.NativeInterop.API..cctor()
   at Microsoft.Identity.Client.NativeInterop.Module.AddRef(String)
   at Microsoft.Identity.Client.NativeInterop.Core..ctor()
   at Microsoft.Identity.Client.Platforms.Features.RuntimeBroker.RuntimeBroker.<>c.<.cctor>b__24_0()
   at Microsoft.Identity.Client.Platforms.Features.RuntimeBroker.RuntimeBroker.<>c.<.cctor>b__24_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper, Boolean)
   at System.Lazy`1.CreateValue()
   at Microsoft.Identity.Client.Platforms.Features.RuntimeBroker.RuntimeBroker.IsBrokerInstalledAndInvokable(AuthorityType)
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsFromBrokerAsync>d__21.MoveNext()
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsInternalAsync>d__20.MoveNext()
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsAsync>d__13.MoveNext()
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsAsync>d__12.MoveNext()

Expected behavior

Works with NativeAOT.

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions