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

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

Open
misteriks opened this issue Mar 24, 2021 · 4 comments

Comments

@misteriks
Copy link

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

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

misteriks commented Mar 25, 2021

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

@jasoth any idea when this PR will get released?

@jazuntee
Copy link
Contributor

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.

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

4 participants