Skip to content

Loading nuget with referenced modules - Weird behavior  #9846

@mikeTWC1984

Description

@mikeTWC1984

Environment: Win 10, ps 5.1 and Powershell Core

I'm adding DB2 database driver to my PS script. That driver is a .net core wrapper for non C# client. Nuget name is IBM.Data.DB2.Core. Dotnet driver is located in lib\netstandard2.0 folder as usually, but actual client is in build\clidriver folder. If I would build dotnet console app, it would put that clidriver folder in the same directory with IBM.Data.DB2.Core.dll. This approach would work if I run script in powershell 5.1 console. However if I run it in Pwsh Core, or even in ISE, it can't figure out where clidriver folder is (and throw weird error). This can be fixed if I add this dll from the original location (lib/netstandard), somehow it knows nuget folder structure.
Wondering if there is a way to push pwsh core to look for clidriver folder in current directory (like PS5 or console app do)? Below is a script you can use for testing. No need to set up database, just see if you get error from DB client (on success) or some weird unrelated error

Steps to reproduce

<# Initial setup  (Windows 10, ps 5.1)

nuget install IBM.Data.DB2.Core

# copying dependencies like console app would do

Copy-Item .\IBM.Data.DB2.Core.1.3.0.100\build\clidriver -Recurse -Destination "."
Copy-Item .\IBM.Data.DB2.Core.1.3.0.100\lib\netstandard2.0\IBM.Data.DB2.Core.dll -Destination "."

#>




# If you copy clidriver and target dll to your project folder (like console app) it will only work in Powershell 5 console
# It will fail in ISE, powershell core and VSCode
 Add-Type -path .\IBM.Data.DB2.Core.dll # assuming clidriver folder is copied here too.

 
# But it will work everywhere if adding DLL from \lib\netstandard
# Somehow it knows nuget structure and uses modules from \buid\clidriver
# Add-Type -Path .\IBM.Data.DB2.Core.1.3.0.100\lib\netstandard2.0\IBM.Data.DB2.Core.dll

# ------------------------ Test Script ----------------------------------------------------------- #

$str = "Database=sysadmin;User ID=informix;Password=in4mix;Server=localhost:9089;"
$cn  = New-Object IBM.Data.DB2.Core.DB2Connection $str


$cn.Open() # On success you should see ERROR [08001] [IBM] SQL1336N (that comes from db client)
           # On error you'll see "Length cannot be less than zero" (so it can't refer to clidriver folder)
$cn.Close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions