But when I want to use this code (minus Dashboard of course) in a Script like so:
# It all starts with a single line of powershell code.
Set-TransmissionCredentials -Host "http://host.docker.internal:8086/transmission/rpc" -User "" -Password ""
[array]$torrents = Get-TransmissionTorrents
I get this error:
[error] Failed to retrieve torrents with error: One or more errors occurred. (Could not load file or assembly ‘Flurl.Http, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null’. Could not find or load a specific file. (0x80131621))
I can see that the module is not able to load a depending DLL but why?
If this works for a Dashboard then why not inside a Script?
Assembly load conflicts are a general problem with PowerShell and .NET. Typically, with .NET projects, assembly conflicts are detected and resolved at compile time. Because PS loads assemblies dynamically, you won’t run into issues until runtime, like you are seeing. This could happen if you mixed two modules that use the same library (for example, Flurl) in an PowerShell prompt.
The problem is that the Universal module uses Flurl as well and it’s using an older version of the library than the Transmission module. It is happening to load it before Transmission has a chance to and that’s causing the issue. For whatever reason, the dashboard is not loading Flurl and Transmission gets a chance to load it’s copy first and that’s why it works.
Assembly loading isn’t something we control directly and the .NET runtime is taking care of that. I think our solution here would be to upgrade Flurl in PSU so that it’s the same or newer than the one used in Transmission.