AzureAD / MSAL.PS

MIT License
159 stars 29 forks source link

New-MsalClientApplication : Cannot convert argument "builder" #68

Open JorgaWetzel opened 1 year ago

JorgaWetzel commented 1 year ago

Hello,

I was able to successfully send this command:

Connect-MgGraph $Current_MgContext = Get-MgContext $Global:AccessToken = Get-MsalToken -ClientID $Current_MgContext.ClientId -TenantId $Current_MgContext.TenantId

but then suddenly i have this persistent error:

New-MsalClientApplication : Cannot convert argument "builder", with value: "Microsoft.Identity.Client.PublicClientApplicationBuilder", for "WithDesktopFeatures" to type "Microsoft.Identity.Client.PublicClientApplicationBuilder": "Cannot convert the "Microsoft.Identity.Client.PublicClientApplicationBuilder" value of type "Microsoft.Identity.Client.PublicClientApplicationBuilder" to type "Microsoft.Identity.Client.PublicClientApplicationBuilder"." At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Select-MsalClientApplication.ps1:56 char:29

But this error is machine dependent, on another PC it runs fine.

ramonrub commented 1 year ago

same problem ... any suggestions please?

cgyim commented 1 year ago

same problem, MSAL.ps version 4.35.1.3

PascalVerbruggen commented 1 year ago

The explanation is simple. I have no idea about a structural solution that will keep working. The workaround is easy: import-module msal.ps import-module microsoft.graph.authentication [Microsoft.Identity.Client.PublicClientApplicationBuilder].Assembly

GAC Version Location

False v4.0.30319 C:\Program Files\WindowsPowerShell\Modules\msal.ps\4.37.0.0\Microsoft.Identity.Client.4.37.0\net45\Microsoft.Identity.Client.dll => It works.

import-module microsoft.graph.authentication import-module msal.ps [Microsoft.Identity.Client.PublicClientApplicationBuilder].Assembly

GAC Version Location

False v4.0.30319 C:\Program Files\WindowsPowerShell\Modules\microsoft.graph.authentication\1.28.0\Dependencies\Desktop\Microsoft.Identity.Client.dll => It doesn't work. This is an older version.

Here it appears to work by simply switching the order. I don't know if there are any side effects.

Some indications of better solutions are in here. (Basically it says "don't run both assemblies in same process".) https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.3

RuneHL commented 9 months ago

Had the same issue; in my case it looks like it is caused when using webview2 for interactive login. Adding the lines below to my script (i.e. not changing the module code) fixed the issue so the popup browser window for auth. is displayed. Not pretty...suggest that an option is added to allow disabling use of webview2.

import-module msal.ps import-module microsoft.graph.authentication $r=Get-Module -Name msal.ps $t=$r.SessionState.PSVariable.GetValue('ModuleFeatureSupport',$null) $t.WebView2Support=$false Get-MsalToken -ClientId ............