Error while using Octopus.Client in C# Script

I created a step which executes C# script using Octopus.Client but when executed, it fails with below error:

ERROR: Script compilation failed. [CompilationErrorException] C:\Octopus\Work\20221124025558-346424-11426\Script.csx(10,22): error CS0012: The type ‘Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘netstandard, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’.

Below is first few lines of code of Script which shows, how I referenced it

#r "Octopus.Client/lib/netstandard2.0/Octopus.Client.dll"

using Octopus.Client;
using Octopus.Client.Model;

var octopusURL = "";
var octopusAPIKey = "";

var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey);
var repository = new OctopusRepository(endpoint);

Below is screen shot of settings of script execution details:

And referenced below 3 packages:

I tried all things but it still failing, any suggestion / help to solve this error will be great.


Hi @shahtarakh

Since you are referencing the Octopus.Client library on the fly when deployed, and this is being deployed to a worker; the reference folder for the client will change each time. When a package is extracted for a script, it’s put into a “Work” folder with the folder made up of the date-time, thread number, and task count. Since it’s different every time, trying to do it in this way will be next to impossible since we don’t have any variables with the thread or task counts.

If you wish to use the client, I’d recommend making a custom worker and putting the client library somewhere you know so you can access it directly by referencing the file path at the top.

We also try to steer customers away from using the client library since some functionality is mismatched with the API, and sometimes desired data can’t be found. I’d recommend using web requests to query the API directly instead of utilising the client, but at the end of the day, it’s down to what you’d like to use.

If you have any further questions, please let me know!
Kind Regards

Hi again @shahtarakh

It seems I was incorrect about the work folder being an issue! I’ve just tested it with my reference below, and the script didn’t have an error.

#r "./Octopus.Client/lib/net462/Octopus.Client.dll"

This is using the latest version of the Octopus client from NuGet, and I did not include any other packages to be unpacked.

Let me know how this goes.
Kind Regards

Thanks @sean.stanway Its working fine now. I changed


#r "Octopus.Client/lib/netstandard2.0/Octopus.Client.dll"


#r "./Octopus.Client/lib/net462/Octopus.Client.dll"

and keep only Octopus.Client as package reference.

Just for reference, I look into below Octopus documentation page, so might be worth changing if this applies to all users.

Hi @shahtarakh

Glad to hear that’s working for you now. I’ll have a look into what needs to be done for making the .NET standard reference to work and we’ll update the documentation accordingly.

Kind Regards

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