Topic "Add_type not working"

Author Message
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I have upgraded to WINSCP 5.9.5 Automation. My scripts all fail with the Add-type command:

Add-Type : Could not load file or assembly 'file:///C:\Program Files (x86)\WinSCP\WinSCPnet.dll' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515)

After that error, none of the later winscp calls within the script will function.

Someone, please send me some advice on how to resolve this.

Note: my server is Windows 2012-R2 64bit.
Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
Please read documentation:
https://winscp.net/eng/docs/message_net_operation_not_supported
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I unblocked the DLL and this is what I get when I attempt to run the PS1 script:

Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
$sessionOptions = New-Object -ComObject WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "myserver"
UserName = "myuser"
Password = "mypassword"
SshHostKeyFingerprint = "ssh-rsa 2048 fc:44:00:23:f2:8a:aa:00:64:f2:d8:36:4c:2e:6d:f1"
}

New-Object : Retrieving the COM class factory for component with CLSID {2D4EF368-EE80-4C15-AE77-D12AEAF4B00A} failed due to the following error:
80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:19 char:19
+ $sessionOptions = New-Object -ComObject WinSCP.SessionOptions -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Smile [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
Please do not crosspost:
https://winscp.net/forum/viewtopic.php?p=78018#78018
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
This is directly from the "Using WinSCP .NET Assembly from PowerShell"
It clearly shows the 'Add-Type' command.


This example is functionally equivalent to overall C# example for WinSCP .NET assembly.
There are also other PowerShell examples.

try
{
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "example.com"
UserName = "user"
Password = "mypassword"
SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I ran the same code on my Windows 7 64bit PC and it works fine, but does not work on the Windows 2012 R2 64bit server.
Winscp_Test_ps1.txt (995 Bytes) Private file

Description: the script

winscp_20170530.log (7.9 KB) [Download]

Description: the log

martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
Can you please stop skipping between the two topics?

I never wrote that you should not use Add-Type.

I've asked you (in the other topic), why do you instantiate the class via COM - The -ComObject switch.

Though the switch is not anymore in the latest code you have posted. But you didn't show us, what problem (if any) do you have with the latest code. It must be a different problem, than you had with the previous code.
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I got it working finally.
My apology for jumping between the 2 posts.

I removed the "Block" on the DLL properties and re-registered it.
I removed the -ComObject.
Before the Add-Type, I do CD to the folder where the DLL is installed.
Now the command is simply the DLL name.

Thanks for you assistance and patience.
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
No need to register the assembly for use from PowerShell using Add-Type.
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License