Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembly conflict with Pnp.PowerShell #1

Open
fornax-a opened this issue May 21, 2022 · 2 comments
Open

Assembly conflict with Pnp.PowerShell #1

fornax-a opened this issue May 21, 2022 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@fornax-a
Copy link

I am attempting to rationalise our PowerShell logging technique across numerous scripts, but have encountered an unfortunate conflict with the Microsoft module Pnp.PowerShell.

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileLoadException: Assembly with same name is already loaded
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
   at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
   at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
   at PnP.Framework.Http.PnPHttpClient.BuildServiceFactory()
   at PnP.Framework.Http.PnPHttpClient..ctor()
   at PnP.Framework.Http.PnPHttpClient.<>c.<.cctor>b__15_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location where exception was thrown ---
   at System.Lazy`1.CreateValue()
   at PnP.Framework.Http.PnPHttpClient.get_Instance()
   at PnP.Framework.Http.MsalHttpClientFactory.GetHttpClient()
   at Microsoft.Identity.Client.Http.HttpManager.GetHttpClient()
   at Microsoft.Identity.Client.Http.HttpManager.ExecuteAsync(Uri endpoint, IDictionary`2 headers, HttpContent body, HttpMethod method, ICoreLogger logger, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Http.HttpManager.ExecuteWithRetryAsync(Uri endpoint, IDictionary`2 headers, HttpContent body, HttpMethod method, ICoreLogger logger, Boolean doNotThrow, Boolean retry, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Http.HttpManager.SendGetAsync(Uri endpoint, IDictionary`2 headers, ICoreLogger logger, Boolean retry, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders)
   at Microsoft.Identity.Client.OAuth2.OAuth2Client.DiscoverAadInstanceAsync(Uri endPoint, RequestContext requestContext)
   at Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.SendInstanceDiscoveryRequestAsync(Uri authority, RequestContext requestContext)
   at Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.FetchAllDiscoveryMetadataAsync(Uri authority, RequestContext requestContext)
   at Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.GetMetadataAsync(Uri authority, RequestContext requestContext)
   at Microsoft.Identity.Client.Instance.Discovery.InstanceDiscoveryManager.FetchNetworkMetadataOrFallbackAsync(RequestContext requestContext, Uri authorityUri)
   at Microsoft.Identity.Client.Instance.Discovery.InstanceDiscoveryManager.GetMetadataEntryAsync(AuthorityInfo authorityInfo, RequestContext requestContext, Boolean forceValidation)
   at Microsoft.Identity.Client.Instance.AuthorityManager.RunInstanceDiscoveryAndValidationAsync()
   at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.ExecuteAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenByUsernamePasswordParameters usernamePasswordParameters, CancellationToken cancellationToken)
   at PnP.Framework.AuthenticationManager.GetContextAsync(String siteUrl, CancellationToken cancellationToken)
   at PnP.Framework.AuthenticationManager.GetContext(String siteUrl)
   at PnP.PowerShell.Commands.Base.PnPConnection.CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCredential credentials, Boolean currentCredentials, String tenantAdminUrl, AzureEnvironment azureEnvironment, String clientId, String redirectUrl, Boolean onPrem, InitializationType initializationType) in c:\build\src\Commands\Base\PnPConnection.cs:line 372
   at PnP.PowerShell.Commands.Base.ConnectOnline.ConnectCredentials(PSCredential credentials, InitializationType initializationType) in c:\build\src\Commands\Base\ConnectOnline.cs:line 514
   at PnP.PowerShell.Commands.Base.ConnectOnline.Connect(CancellationToken& cancellationToken) in c:\build\src\Commands\Base\ConnectOnline.cs:line 260
   at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord() in c:\build\src\Commands\Base\ConnectOnline.cs:line 210
   at System.Management.Automation.CommandProcessor.ProcessRecord()

PoShLog is pretty awesome and I would very much like to utilise wherever possible - Please do advise whether we have any option to workaround this issue.

@TomasBouda TomasBouda added the bug Something isn't working label May 22, 2022
@TomasBouda
Copy link
Member

Hi, I think I've seen similar issue in past, but unfortunately so far I don't have resolution for it.
I'm gonna need some time to figure it out. 😅 Or perhaps someone else can help with this? 🆘

@TomasBouda TomasBouda added the help wanted Extra attention is needed label May 22, 2022
@fornax-a
Copy link
Author

Many thanks for coming back so quickly, I realise this may not be a quick fix. Still working my way though the following article, but it makes for interesting (and hopefully promising) reading.

https://devblogs.microsoft.com/powershell/resolving-powershell-module-assembly-dependency-conflicts/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants