Skip to content

[Bug] MSAL Broker unable to load 'msalruntime.dll' when packaged as MSIX #3740

@exchange321

Description

@exchange321

Logs and network traces

Microsoft.Identity.Client.MsalClientException: Unable to load DLL 'msalruntime': The specified module could not be found. (Exception from HRESULT: 0x8007007E) See https://aka.ms/msal-net-wam#troubleshooting ---> System.DllNotFoundException: Unable to load DLL 'msalruntime': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Identity.Client.NativeInterop.API.x64.MSALRUNTIME_Startup()
   at Microsoft.Identity.Client.NativeInterop.API.x64.Startup()
   at Microsoft.Identity.Client.NativeInterop.Module.AddRef(String handleName)
   at Microsoft.Identity.Client.NativeInterop.Core..ctor()
   at Microsoft.Identity.Client.Broker.RuntimeBroker.<>c.<.cctor>b__21_0()
   --- End of inner exception stack trace ---
   at Microsoft.Identity.Client.Broker.RuntimeBroker.<>c.<.cctor>b__21_0()
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at Microsoft.Identity.Client.Broker.RuntimeBroker.IsBrokerInstalledAndInvokable(AuthorityType authorityType)
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsFromBrokerAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsInternalAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.ClientApplicationBase.<GetAccountsAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Clipchamp.Domain.Services.MicrosoftAuthService.<ClearCache>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Clipchamp.Domain.Services.MicrosoftAuthService.<SignIn>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Clipchamp.Domain.Handlers.SignInWithMicrosoftHandler.<Handle>d__4.MoveNext()
Inner Exception: System.DllNotFoundException: Unable to load DLL 'msalruntime': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Identity.Client.NativeInterop.API.x64.MSALRUNTIME_Startup()
   at Microsoft.Identity.Client.NativeInterop.API.x64.Startup()
   at Microsoft.Identity.Client.NativeInterop.Module.AddRef(String handleName)
   at Microsoft.Identity.Client.NativeInterop.Core..ctor()
   at Microsoft.Identity.Client.Broker.RuntimeBroker.<>c.<.cctor>b__21_0()

Which version of MSAL.NET are you using?
Microsoft.Identity.Client 4.47.2
Microsoft.Identity.Client.Broker 4.47.2-preview
Microsoft.Identity.Client.NativeInterop 0.13.0

Platform
C# WPF (.NET Framework 4.8) packaged as MSIX through Windows Application Packaging Project

What authentication flow has the issue?
WAM

Is this a new or existing app?
Discovered the issue when migrating from Microsoft.Identity.Client.Desktop to Microsoft.Identity.Client.Broker as per this documentation

Repro

  • Clone the repo. (https://github.com/gladjohn/WPF-NativeDll-LoadIssue)
  • Build the solution to restore all nuget packages.
  • Start the project "WPF" project.
  • You will be displayed with a window with a button and a text box
  • Click on the Acquire Token Interactively button

Result : You should now see the Windows Web Account Manager UI showing up and prompting you to sign in to the app. You can use the MS Credentials or use the following user details to sign-in. But sign in is actually not required. The WAM (Web Account Manager) UI is from the Native dll (msalruntime.dll) packaged along with Microsoft.Identity.Client.Broker

  • Now set the WPF.Package as the start up project
  • Start the project "WPF.Package" project.

Error :

Microsoft.Identity.Client.MsalClientException: 'Unable to load DLL 'msalruntime': The specified module could not be found. (Exception from HRESULT: 0x8007007E) See https://aka.ms/msal-net-wam#troubleshooting'

Inner Exception
DllNotFoundException: Unable to load DLL 'msalruntime_x86': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Extended error info and workarounds can be found in the repo link

Expected behavior
Using WAM as a broker should not fail

Actual behavior
MSAL throws Microsoft.Identity.Client.MsalClientException: Unable to load DLL 'msalruntime': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Metadata

Metadata

Assignees

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