dbatools
dbatools copied to clipboard
Conflict with MSAL.ps - works interactively but not when noninteractive
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
PS>TerminatingError(Add-Type): "Assembly with same name is already loaded"
when noninteractive, I receive this error and it does not proceed
when interactive, I get...
WARNING: Assembly with same name "Microsoft.Identity.Client.dll" is already loaded:
C:\Program Files\PowerShell\Modules\dbatools.library\2023.5.5\core\lib\win-sqlclient\Microsoft.Identity.Client.dll
but the script continues.
ModuleType Version PreRelease Name Script 2.0.4 dbatools Script 2023.5.5 dbatools.library Script 4.37.0.0 MSAL.PS Script 22.1.1 SqlServer
I am running the following command when it fails
$Token = Get-MsalToken -ClientId $clientID -ClientSecret $secsecret -TenantId $TenantID -Scopes $Scopes -Verbose -ForceRefresh
The reproduction steps were only showing an error when run non-interactively.
REQUEST: Some config item that allows you to use the full MSAL.ps when loaded.
Steps to Reproduce
import-module dbatools
import-module SQLServer
$Token = Get-MsalToken -ClientId $clientID -ClientSecret $secsecret -TenantId $TenantID -Scopes $Scopes -Verbose
Please confirm that you are running the most recent version of dbatools
Yes, 2.0.4 as of this porting
Other details or mentions
No response
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
7.3.6
SQL Server Edition and Build number
Microsoft SQL Server 2014 (SP3-GDR) (KB5014165) - 12.0.6169.19 (X64) Apr 21 2022 18:01:27 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
.NET Framework Version
.NET 7.0.9
We do not own the MSAL module so I'm not sure what you are asking here?
This is not much different than using dbatools with sqlserver modules together will cause various issues. If you work on the import order of the modules that reference the same assembly you might be able to get passed the error.
Non-interactively, i cannot load both MSAL.ps and dbatools. the library includes a DLL that MSAL.ps uses and they are conflicting.
Truthfully I'm not sure what we can do for you. This is the behavior of PowerShell here as first-come-first-serve with Assemblies being loaded.
when I do them in the opposite order, i get a similar error.
` PS C:\Windows\System32> import-module msal.ps PS C:\Windows\System32> import-module dbatools
Exception: Couldn't import C:\Program Files\PowerShell\Modules\dbatools.library\2023.5.5\core\lib\win-sqlclient\Microsoft.Data.SqlClient.dll | Could not load file or assembly 'Microsoft.Identity.Client, Version=4.47.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)`
Relevant Issue. https://github.com/dataplat/dbatools/issues/9334