Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

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

Open
JorgaWetzel opened this issue May 2, 2023 · 4 comments
Open

Comments

@JorgaWetzel
Copy link

JorgaWetzel commented May 2, 2023

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

  • ... plication = New-MsalClientApplication -ErrorAction Stop @paramNewMsal ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [New-MsalClientApplication], MethodException
    • FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument,New-MsalClientApplication

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

@ramonrub
Copy link

ramonrub commented Jun 5, 2023

same problem ... any suggestions please?

@cgyim
Copy link

cgyim commented Jun 14, 2023

same problem, MSAL.ps version 4.35.1.3

@PascalVerbruggen
Copy link

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
Copy link

RuneHL commented Sep 21, 2023

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 ............

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants