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

"Could not load file or assembly 'System.ServiceModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'." #21527

Closed
5 tasks done
prajasek-netapp opened this issue Apr 24, 2024 · 3 comments

Comments

@prajasek-netapp
Copy link

Prerequisites

Steps to reproduce

I am not able to load the module, which has System.ServiceModel.Primitives dependency.

Simply load the module in the powershell 7.
Example:-

[System.Reflection.Assembly]::LoadFrom('< path to the folder contains System.ServiceModel.Primitives.dll>')

Add-Type -Path "< path to the folder contains System.ServiceModel.Primitives.dll>"

Both the commands results in Could not load file or assembly 'System.ServiceModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Expected behavior

PS C:\Users\Administrator> [System.Reflection.Assembly]::LoadFrom('C:\_RajRepo\Master\orion\cliffhanger\Bin\Debug\net8.0\publish\win-x64\System.ServiceModel.Primitives.dll')

PS C:\Users\Administrator> Add-Type -Path "C:\_RajRepo\Master\orion\cliffhanger\Bin\Debug\net8.0\publish\win-x64\System.ServiceModel.Primitives.dll"


Expectation - should load the dll

Actual behavior

PS C:\Users\Administrator> [System.Reflection.Assembly]::LoadFrom('C:\_RajRepo\Master\orion\cliffhanger\Bin\Debug\net8.0\publish\win-x64\System.ServiceModel.Primitives.dll')
MethodInvocationException: Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'System.ServiceModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
PS C:\Users\Administrator> Add-Type -Path "C:\_RajRepo\Master\orion\cliffhanger\Bin\Debug\net8.0\publish\win-x64\System.ServiceModel.Primitives.dll"
Add-Type: Could not load file or assembly 'System.ServiceModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Error details

Could not load file or assembly 'System.ServiceModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Environment data

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@prajasek-netapp prajasek-netapp added the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 24, 2024
@rhubarb-geek-nz
Copy link

Hi, I suggest it is a conflict with PowerShell's version of the library. It own's the process and is likely to have loaded that first.

PS C:\Program Files\PowerShell\7> (Get-Item -LiteralPath System.ServiceModel.Primitives.dll).VersionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
3.4.3            4.1000.323.51101 C:\Program Files\PowerShell\7\System.ServiceModel.Primitives.dll

If you are just writing a script then you have a major challenge, but if you are writing a C #cmdlet then you can set up an Assembly Load Context.

The problem is a single load context can only load one version of a named shared assembly. So you can create a child load context and load your conflicting assemblies into that.

I have just just gone through this process with one of my modules, where I load the Postgres Database Connection into the child Assembly Load Context but can share objects created within that load context through my cmdlet, the Alc module is the bridging assembly that allows objects to be shared across the divide.

The assemblies within the lib directory run in the child Alc.

  • rhubarb-geek-nz.NpgsqlConnection.nuspec
  • README.md
  • rhubarb-geek-nz.NpgsqlConnection.psd1
  • RhubarbGeekNz.NpgsqlConnection.dll
  • lib\Microsoft.Extensions.Logging.Abstractions.dll
  • lib\Npgsql.dll
  • lib\RhubarbGeekNz.NpgsqlConnection.Alc.dll

Copy link
Contributor

microsoft-github-policy-service bot commented May 3, 2024

📣 Hey @prajasek-netapp, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage The issue is new and needs to be triaged by a work group. label May 3, 2024
@prajasek-netapp
Copy link
Author

Thanks, it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants