AzureAD / MSAL.PS

MIT License
159 stars 29 forks source link

ERROR: Assembly with same name is already loaded when running in Azure Function #31

Open misteriks opened 3 years ago

misteriks commented 3 years ago

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?

muzzar78 commented 3 years ago

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

misteriks commented 3 years ago

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

smokedlinq commented 3 years ago

@jasoth any idea when this PR will get released?

jazuntee commented 2 years ago

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.