Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
azchohfi opened this issue Nov 17, 2023 · 6 comments
Closed

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

azchohfi opened this issue Nov 17, 2023 · 6 comments

Comments

@azchohfi
Copy link

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

@azchohfi azchohfi added untriaged Do not delete. Needed for Automation needs attention Delete label after triage labels Nov 17, 2023
@azchohfi
Copy link
Author

Related issue: #4424

@bgavrilMS
Copy link
Member

This bug will have been fixed in the broker interop https://github.com/AzureAD/microsoft-authentication-library-for-cpp/pull/3807/files (private repo) but not yet released.

@ashok672, @iulico-1 - regular release goes out every Thu of every month, so next one is scheduled on Dec 7. Happy to help with an out of band release if needed by partners.

@bgavrilMS bgavrilMS added bug public-client WAM and removed untriaged Do not delete. Needed for Automation needs attention Delete label after triage labels Nov 17, 2023
@bgavrilMS bgavrilMS added this to the 4.58.0 milestone Nov 17, 2023
@pmaytak
Copy link
Contributor

pmaytak commented Nov 29, 2023

Released in 4.58.0.

@pmaytak pmaytak closed this as completed Nov 29, 2023
@azchohfi
Copy link
Author

I'm still having issues even with 4.58.0:

Unhandled exception: System.IO.FileNotFoundException: Could not find file 'System.Windows.Forms'.
File name: 'System.Windows.Forms'
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateFileNotFoundException(ExceptionStringID, String) + 0x43
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowFileNotFoundException(ExceptionStringID, String) + 0x9

Maybe it is related to this?
dotnet/winforms#4649

@azchohfi
Copy link
Author

I did have an ILC warning during my compilation, mentioning exactly that method:
2>ILC: Method '[msstore]MSStore.CLI.Services.TokenManager.MSALTokenManager+<InitAppAsync>d__16.MoveNext()' will always throw because: Failed to load assembly 'System.Windows.Forms'

@azchohfi
Copy link
Author

Oh, actually that was a misconfiguration in my compilation. I had SelfContained=false. It had to be true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants