PowerShell script requires missing .NET packages

I am working on a PowerShell script for use in a rule.

The script needs to load the ActiveDirectory module to function.  The ActiveDirectory Module requires System.ServiceModel.NetTcp under PWSH to run, however that is not currently available to the PowerShell libraries that are used by the Syslog NG service. 

The script runs when I run it on my development system, but I have PowerShell 7.4.6 which contains the full .NET 8.0.10 framework.

Is there a way to install / reference the missing .NET components/packages so that the script can function?  I have found them on NuGet, but I doubt it is as simple as copying the DLLs into the service directory. 

EDIT:  

For reference, the error being thrown is:

TerminatingError(Get-ADObject): "Could not load file or assembly 'System.ServiceModel.NetTcp, Version=4.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified."

Thanks,

Eric

  • As suspected, simply dropping the DLL in the service directory did not work.  Likely because the application was not compiled with that DLL in the reference list, so the it doesn't know to try and load it.

    After further examination, I determined that the DLLs in the service directory are versioned with versions that ship with Powershell 7.  However, the PowerShell DLL version doesn't seem to match what ships with the full PowerShell 7, so it took a bit of searching to find the correct DLL version.  Also it is unclear if they are using 32-bit or 64-bit (although the .NET DLLs might be universal - I tried both anyhow).

    So now I need to determine how/if it is possible to reference the DLL within the script.

  • I have discovered a couple things: (1) a workaround and (2) where the DLLs are loaded by the service

    The Workaround

    I'm not sure how reliable this is, so I'm going to watch the logs I'm having the script generate to see if it continues to run as expected. Here is what I did:

    1. Drop the DLL in the service directory ( X:\Program Files (x86)\SolarWinds\Kiwi Syslog Server NG\ ).  Technically it could go anywhere, but I put it there for cleanliness.

    2. Create a PowerShell script (e.g. load_System-ServiceModel-NetTcp.ps1 ) with the following code:

    using assembly "X:\Program Files (x86)\SolarWinds\Kiwi Syslog Server NG\System.ServiceModel.NetTcp.dll"
    using namespace System.ServiceModel.NetTcp

    3. Upload the above script to the Syslog Server NG (under Setup > Scripts)

    4. In your rule, add this script as an action that runs before your main script.  

    For whatever reason, I was unable to load the assembly and make a call to it within the same script.  But I discovered that once it is loaded, you can call it from a subsequent script.  

    DLLs loaded by the service

    The DLLs loaded by the service are defined in X:\Program Files (x86)\SolarWinds\Kiwi Syslog Server NG\SolarWinds.Kiwi.Syslog.Service.deps.json .  This file appears to be generated when the application is compiled, as there are numerous references to NuGet packages and Hash information for them.  However, It is more complicated that simply telling it to load the DLL.  If I were a programmer, I could probably figure it out. The NuGet package really needs to be referenced in the project.

    Not the cleanest solution, but it seems to work.  If anyone finds a better solution, I would be interested in seeing it.

    If the Solarwinds dev team is reading, please add the full .NET 8 framework to the application like PowerShell 7 does (especially the WCF libraries / assemblies).