Using Octopus.Client.dll via PowerShell

Hi,

I’m trying to write a script that will use Octopus.Client.dll, however I am having difficulty adding the assembly. I’ve downloaded OctopusToolsPortable 4.31.1 from nuget.org, but when I run Add-Type -Path "Octopus.Client.dll", I receive the error:

Message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
StackTrace:    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes)
   at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

According to your article here, this should work.

My guess is that System.ComponentModel.Annotations is missing. I’ve downloaded version 4.1.0, but there are DLLs in lib and ref for various versions of .NET and I am not sure which one I should use. I’ve tried copying every single .dll, one at a time, into the OctopusToolsPortable directory, but I get the same error.

Is this a bug or am I missing something trivial?

Any help will be greatly appreciated.

Thanks

W.

P.S. I know about OctoPosh, but it is missing the capability to delete releases. I had a look at modifying OctoPosh but I ran into difficulties and as you can tell my programming skills are not up to the task.

Full PowerShell command and output:

try
{
    Add-Type -Path "C:\Temp\OctopusTools.4.31.1.portable\Octopus.Client.dll"
}
catch [System.Reflection.ReflectionTypeLoadException]
{
   Write-Host "Message: $($_.Exception.Message)"
   Write-Host "StackTrace: $($_.Exception.StackTrace)"
   Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
}


Message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
StackTrace:    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes)
   at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
 System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
 System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
 System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ComponentModel.Annotations, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Hi @Tex, thanks for reaching out.

There are some steps you can take to try and resolve the issue.

First, grab the Octopus.Clients package from https://www.nuget.org/packages/Octopus.Client/. The clients package is how the library is distributed, while the tools library has a lot of other files for running the CLI that are unnecessary for writing scripts in Powershell.

Second, install the latest version of Powershell Core from https://github.com/PowerShell/PowerShell/releases.

There are two folders in the clients library: /lib/net45 and /lib/netstandard2.0. From a Powershell Core terminal, add the dll file from the netstandard2.0 directory.

That should then allow you to import the dll file and work with it in a Powershell script.

Regards
Matt C

Hi @Matthew_Casperson,

Thanks for your reply.

Are you saying I need to be using PS version 6. Does it not work with PS 5.1?

What is the difference between the Octopus.Client and OctopusToolsPortable package?

Do you mean the System.ComponentModel.Annotations.dll file?

Thanks Again.
T.

Hi @Tex,

Are you saying I need to be using PS version 6. Does it not work with PS 5.1?

It should work with PS 5.1, but using the latest version of PS is one of the common troubleshooting steps.

What is the difference between the Octopus.Client and OctopusToolsPortable package?

The clients package is how the library is distributed, so it includes only the DLL files for different versions of .NET. The tools library has a lot of other files for running the CLI that are unnecessary for writing scripts in Powershell.

Do you mean the System.ComponentModel.Annotations.dll file?

No, sorry, I was referring to the Octopus.Clients.dll file.

Regards
Matt C

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