Prerequisites
Steps to reproduce
-
Windows PowerShell provides a meaningful error message in response to attempts to call P/Invoke declarations compiled via Add-Type that mistakenly reference a nonexistent DLL ("Unable to load DLL 'NoSuch.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)")
-
In PowerShell Core, the following misleading / obscure error is reported instead:
"Value cannot be null. (Parameter 'path1')"
# Try to call a function from a NONEXISTENT DLL via P/Invoke.
(Add-Type -ErrorAction Stop -NameSpace NS$PID -Name Aux -PassThru @'
[DllImport("NoSuch.dll", CharSet = CharSet.Unicode)]
public static extern System.UInt16 Foo();
'@)::Foo()
Expected behavior
"Unable to load DLL 'NoSuch.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Actual behavior
"Value cannot be null. (Parameter 'path1')"
That is, the inability to locate the referenced DLL is unexpectedly surfaced via implementation details, confusingly referring to a path1 parameter that is unrelated to the signature of the function being invoked.
Error details
Environment data
Visuals
No response
Prerequisites
Steps to reproduce
Windows PowerShell provides a meaningful error message in response to attempts to call P/Invoke declarations compiled via
Add-Typethat mistakenly reference a nonexistent DLL ("Unable to load DLL 'NoSuch.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)")In PowerShell Core, the following misleading / obscure error is reported instead:
"Value cannot be null. (Parameter 'path1')"Expected behavior
"Unable to load DLL 'NoSuch.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"Actual behavior
"Value cannot be null. (Parameter 'path1')"That is, the inability to locate the referenced DLL is unexpectedly surfaced via implementation details, confusingly referring to a
path1parameter that is unrelated to the signature of the function being invoked.Error details
Environment data
Visuals
No response