MSAL.PS
MSAL.PS copied to clipboard
ERROR: Assembly with same name is already loaded when running in Azure Function
I'm trying to get this to work in a Azure Powershell function (httptrigger)
Test code I have is the following
Import-Module MSAL.PS
$TenantId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$ClientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$CertThumbPrint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$connectionDetails = @{
'TenantId' = $TenantId
'ClientId' = $ClientId
'ClientCertificate' = Get-Item -Path "Cert:\CurrentUser\My\$CertThumbPrint"
}
$Token = Get-MsalToken @connectionDetails
Local in vs code debug it works fine. However, when testing this code in Azure I get the following error
2021-03-24T15:52:24.871 [Error] ERROR: Assembly with same name is already loadedException :Type : System.IO.FileLoadExceptionMessage : Assembly with same name is already loadedTargetSite :Name : LoadFromPathDeclaringType : System.Runtime.Loader.AssemblyLoadContextMemberType : MethodModule : System.Private.CoreLib.dllStackTrace :at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
I have MSAL.PS 4.21.0.1 included in the Modules folder of the project
Any clue what might be causing this issue and how to resolve it?
I think this is fixed in the following PR that has been merged - #26 A new release hasn't been created but I just updated MSAL.PS.ps1 with the code from the PR and that solved my issue with the dll conflict
thx, I used the updated MSAL.PS.ps1and it is working like a charm in a Azure Function after removing Import-Module MSAL.PS
from my test code
@jasoth any idea when this PR will get released?
Hi everyone, Sorry about the delay. I just released an update (v4.35.1.3) to address this. Hopefully there is a more elegant solution with AssemblyLoadContext that can be implemented at some point in the future but let me know if the updated module works for you.