Unable to load OctopusRepository with Octopus.Server.Client

I am trying to work with the Octopus API using Octopus.Server.Client as documented here: Getting started | Documentation and Support

I have copied the example code (replacing references to Octopus.Client with Octopus.Server.Client) but I get the following error.

PS C:\Users\name> Install-Package Octopus.Server.Client -source https://www.nuget.org/api/v2 -SkipDependencies
PS C:\Users\name> $path = Join-Path (Get-Item ((Get-Package Octopus.Server.Client).source)).Directory.FullName “lib/netstandard2.0/Octopus.Server.Client.dll”
PS C:\Users\name> Add-Type -Path $path
PS C:\Users\name> $server = “xxx”
PS C:\Users\name> $apiKey = “xxx”
PS C:\Users\name> $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($server, $apiKey)
PS C:\Users\name> $repository = New-Object Octopus.Client.OctopusRepository($endpoint)
New-Object: Could not load file or assembly ‘Octopus.Server.MessageContracts.Base, Version=3.1.744.0, Culture=neutral, PublicKeyToken=null’. The system cannot find the file specified.
PS C:\Users\name>

When i try to load the repository in a space context I also get an error:

PS C:\Users\name> $client = New-Object Octopus.Client.OctopusClient($endpoint)
New-Object: Cannot find type [Octopus.Client.OctopusClient]: verify that the assembly containing this type is loaded.

Both of these errors do not occur with Octopus.Client but that library is not usuable for other reasons

Octopus Server v2022.3 (Build 10594)
Octopus.Server.Client.14.2.245

Am i incorrectly loading Octopus.Server.Client objects or have I encountered a bug?

Thanks

Hey @Luke.Powell,

Thanks for reaching out.

Is the Powershell ISE running as an Admin? It looks like it’s possible the assembly is not getting installed properly.

Can I ask if there’s a specific reason you want to use Octopus Client rather than the API itself? Anything you can do in the Client you can do via the API (and more), and we have tons of resources for the API. I’m happy to help get you up and running with the API as well if you’re happy to go that direction.

Looking forward to hearing back.

Best,
Jeremy

Yes powershell is running as an administrator.

We already have written a custom powershell module that abstracts some more complex actions behind powershell cmdlets.
This was all working fine with Octopus.Client until recent version upgrades broke some functionality.
We’d prefer not to have to refactor the entire module to use the rest API.

Note, I am experiencing this issue on multiple machines.

Thanks

Hey Luke,

Sorry about that; that makes total sense.

I’ve done some tinkering on my side and I can’t get it to work with Octopus.Server.Client either.

I’m going to reach out to the developers and get back to you as soon as I can. They are in Australia so we likely won’t hear back until tomorrow at the earliest.

Please feel free to reach out in the meantime.

Best,
Jeremy

Hi Luke,

I’m just jumping on for Jeremy.

This issue wasn’t as simple as we expected. It took some big brains to get around a dependency loop in the package managers and they identified that the following method should work.

I cleaned out all my nuget packages (you can just deleted them from C:\Program Files\PackageManagement\NuGet\Packages

I then ran the following and it did not error


Install-Package NETStandard.Library -source https://www.nuget.org/api/v2 -SkipDependencies Install-Package Octopus.Server.Client -source https://www.nuget.org/api/v2 add-type -path (join-path (get-item ((get-package octopus.server.client).source)).directory.fullname "lib/netstandard2.0/octopus.server.client.dll") add-type -path (join-path (get-item ((get-package octopus.server.messagecontracts.base).source)).directory.fullname "lib/netstandard2.0/octopus.server.messagecontracts.base.dll") add-type -path (join-path (get-item ((get-package octopus.tinytypes).source)).directory.fullname "lib/netstandard2.0/octopus.tinytypes.dll") add-type -path (join-path (get-item ((get-package octopus.tinytypes.json).source)).directory.fullname "lib/netstandard2.0/octopus.tinytypes.json.dll") add-type -path (join-path (get-item ((get-package octopus.tinytypes.typeconverters).source)).directory.fullname "lib/netstandard2.0/octopus.tinytypes.typeconverters.dll") add-type -path (join-path (get-item ((get-package nodatime).source)).directory.fullname "lib/netstandard2.0/nodatime.dll") add-type -path (join-path (get-item ((get-package NodaTime.Serialization.JsonNet).source)).directory.fullname "lib/netstandard2.0/NodaTime.Serialization.JsonNet.dll") $server = "[https://myoctopus.example.com](https://myoctopus.example.com/)" $apiKey = "API-YOURKEY"; $endpoint = New-Object Octopus.Client.OctopusServerEndpoint($server, $apiKey) $repository = New-Object Octopus.Client.OctopusRepository($endpoint) $client = New-Object Octopus.Client.OctopusClient($endpoint)

So as you might be able to see, there was a package dependency loop which was unexpected - regarding NETStandard.Library. Installing NETStandard library separately with no dependencies allows Octopus.Server.Client to install without issues.

You shouldn’t need to remove all your Nuget packages but it’s an option if you are still having problems.

Please let me know how it goes.

Regards,

I cleared the nuget packages and ran the code you provided but it failed on the 2nd line:

Line |
2 | Install-Package Octopus.Server.Client -source https://www.nuget.org/a
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Dependency loop detected for package ‘Octopus.Server.Client’.

I tried this with versions:
14.2.245
14.2.262

Hey Luke,

Thanks for being patient with this one. I’m sorry it didn’t work for you.

It failed for me too. I’m going to get back with our developers and see what might be different on our side vs what they tested with.

Best,
Jeremy

Hey Luke,

The engineers did more testing with the results I gave them and they found it’s not working for me and you because we’re using PowerShell 5 and they’re using PowerShell Core.

Unfortunately, Octopus.Server.Client has some dependencies which do not support .Net Framework (Noda Time), and because of that Octopus.Server.Client won’t work on PowerShell 5, and if you want to use Octopus.Server.Client it will need to be from core.

Please let me know if you’re able to test pwsh core and if it works for you.

Best,
Jeremy

I have been using Powershell 7 (7.6.2) not Powershell Core for all of my testing as Core is now outdated.

Either way, I’m not using Powershell 5 so this is likely not the cause.

Thanks

Hey Luke,

I just tried this block on PowerShell 7 with success:

Install-Package NETStandard.Library -source https://www.nuget.org/api/v2 -SkipDependencies
Install-Package Octopus.Server.Client -source https://www.nuget.org/api/v2

 add-type -path (join-path (get-item ((get-package octopus.server.client).source)).directory.fullname "lib/netstandard2.0/Octopus.Server.Client.dll")
 add-type -path (join-path (get-item ((get-package octopus.server.messagecontracts.base).source)).directory.fullname "lib/netstandard2.0/Octopus.Server.MessageContracts.Base.dll")
 add-type -path (join-path (get-item ((get-package octopus.tinytypes).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.dll")
 add-type -path (join-path (get-item ((get-package octopus.tinytypes.json).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.Json.dll")
 add-type -path (join-path (get-item ((get-package octopus.tinytypes.typeconverters).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.TypeConverters.dll")
 add-type -path (join-path (get-item ((get-package nodatime).source)).directory.fullname "lib/netstandard2.0/NodaTime.dll")
 add-type -path (join-path (get-item ((get-package NodaTime.Serialization.JsonNet).source)).directory.fullname "lib/netstandard2.0/NodaTime.Serialization.JsonNet.dll")

$server = "https://myoctopus.example.com"
$apiKey = "API-YOURKEY";    
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint($server, $apiKey)
$repository = New-Object Octopus.Client.OctopusRepository($endpoint)
$client = New-Object Octopus.Client.OctopusClient($endpoint)

Can you please delete everything in C:\Program Files\PackageManagement\NuGet\Packages(assuming this won’t hurt processes outside of you trying to use this script) and try the above? If you do get an error can you please paste your full output so i can pass it back to our developers?

Best,
Jeremy

If I omit the -Force parameter from this line
Install-Package Octopus.Server.Client -source https://www.nuget.org/api/v2
Then it works after manually approving the installation prompt.

With the -Force parameter (to bypasss the prompt) I get the error
Dependency loop detected for package ‘Octopus.Server.Client’.

Seems the Install-Package has some odd behaviour with force.
As this is to be installed in an automated environment the manual prompt suppression is a requirement so I am still stuck.

Hey Luke,

Thanks for the context. I tested that on my side and also get the dependency loop as well. Let me get with the engineers again and see if there’s a way to solve this.

Best,
Jeremy

Hey Luke,

One of my colleagues was taking a look at this and found a way around this.

Register-PackageSource -Name Nuget.Org -Location https://www.nuget.org/api/v2 -Trusted -ProviderName NuGet

Install-Package Octopus.Server.Client 

If you replace the Install-Package Octopus.Server.Client -source https://www.nuget.org/api/v2 line with this it should go with no prompts and no error. You can remove the trusted source after the process is complete as well if you’re worried the settings will persist outside of the script.

Please let me know if that works.

Best,
Jeremy

I had already tried this but it didn’t work for me. Curious that it worked for you.

PS C:\Users\name> Register-PackageSource -Name Nuget.Org -Location https://www.nuget.org/api/v2 -Trusted -ProviderName NuGet

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
Nuget.Org                        NuGet            True       https://www.nuget.org/api/v2

PS C:\Users\name>
PS C:\Users\name> Install-Package Octopus.Server.Client
Install-Package: Dependency loop detected for package 'Octopus.Server.Client'.

Thanks

Hey Luke,

I created a new VM and installed PowerShell 7.2.6 on it fresh and ran the following and it worked:

Register-PackageSource -Name Nuget.Org -Location https://www.nuget.org/api/v2 -Trusted -ProviderName NuGet

Install-Package NETStandard.Library -SkipDependencies

Install-Package Octopus.Server.Client

add-type -path (join-path (get-item ((get-package octopus.server.client).source)).directory.fullname "lib/netstandard2.0/Octopus.Server.Client.dll")
add-type -path (join-path (get-item ((get-package octopus.server.messagecontracts.base).source)).directory.fullname "lib/netstandard2.0/Octopus.Server.MessageContracts.Base.dll")
add-type -path (join-path (get-item ((get-package octopus.tinytypes).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.dll")
add-type -path (join-path (get-item ((get-package octopus.tinytypes.json).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.Json.dll")
add-type -path (join-path (get-item ((get-package octopus.tinytypes.typeconverters).source)).directory.fullname "lib/netstandard2.0/Octopus.TinyTypes.TypeConverters.dll")
add-type -path (join-path (get-item ((get-package nodatime).source)).directory.fullname "lib/netstandard2.0/NodaTime.dll")
add-type -path (join-path (get-item ((get-package NodaTime.Serialization.JsonNet).source)).directory.fullname "lib/netstandard2.0/NodaTime.Serialization.JsonNet.dll")

$server = "https://"
$apiKey = "API-";
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint($server, $apiKey)
$repository = New-Object Octopus.Client.OctopusRepository($endpoint)
$client = New-Object Octopus.Client.OctopusClient($endpoint)
$repository.Accounts.GetAll()

I did get the dependency loop error when I forgot to put -SkipDependencies on the NETStandard.Library install.

Can you please copy-paste the entire block (with your server and API Key entered into the variables) and see if it works for you?

I’m happy to hop on a call with you to get this worked out if this one doesn’t work.

Please let me know how it goes.

Best,
Jeremy

1 Like

After some tinkering I was able to get this to work.

Are there any plans to fix the original issue of the dependency loop or is the above code block expected to be the intended way to use Octopus.Server.Client from now?

Thanks

Hey Luke,

Awesome news that you’re working now. Let me ask the team and get back with you.

Best,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.