SFTP - VBA/Access - Error automation when creating a Session

Advertisement

gerard_dev
Guest

SFTP - VBA/Access - Error automation when creating a Session

We have downloaded and installed the WinSCP .NET Assembly - and registered it for COM - on a hundred machines, following the same procedure described below.

Configuration :
Windows XP
Access 2003 SP3
WinSCP 5.5.0 (winscp550.zip et winscp550automation.zip) with WinSCP.com, WinSCP.exe and WinSCPnet.dll in the same folder.

We use an Access/VBA program to upload and download files from a SFTP server.
Our code is below :

Registration :
Set WshShell = CreateObject("wscript.shell")
strCommande = """C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" "WinSCPnet.dll" /codebase /tlb"""
WshShell.Run strCommande, 0, True

UN-registration :
Set WshShell = CreateObject("wscript.shell")
strCommande = """C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" "WinSCPnet.dll" /unregister /tlb"""
WshShell.Run strCommande, 0, True

Session options :
Dim mySession As New WinSCPnet.Session
Dim mySessionOptions As New WinSCPnet.sessionOptions
With mySessionOptions
.Protocol = WinSCPnet.Protocol_Sftp
.HostName = strHostName
.PortNumber = lngPortNumber
.SshHostKeyFingerprint = strSshHostKeyFingerprint
.UserName = strUserName
.SshPrivateKeyPath = strSshPrivateKeyPath
End With
mySession.Open mySessionOptions

Registration and un-registration seemed always to work fine, and the Access/VBA program was always able to add a reference to the TLB file.

But for approximately 10 of the 100 machines, we got an "error automation" error (-2146232576 or -2146233321) when creating an instance of the Session class.
On these 10 machines, we have uninstalled and unregistered all the versions of WinSCP.dll and WinSCPnet.dll and reinstalled and re-registered the WinSCP .NET Assembly (5.5.0), but we get always the same "error automation" errors.

What can we do ?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: SFTP - VBA/Access - Error automation when creating a Session

After unregistering WinSCPnet.dll, try searching Windows Registry for any instance of "winscp" and remove it. That's all I can recommend, without knowing what's different about your 10 machines.
_________________
Martin Prikryl

Reply with quote

gerard_dev
Guest

Re: SFTP - VBA/Access - Error automation when creating a Session

martin wrote:

After unregistering WinSCPnet.dll, try searching Windows Registry for any instance of "winscp" and remove it. That's all I can recommend, without knowing what's different about your 10 machines.

Unfortunately, we already had this idea of searching Windows Registry for any instance of "winscp" and removing it, and that did not solve our problem.
And the only difference of the 10 machines with the others is precisely that the DLL can be registered on them but is nevertheless not usable by VBA.

In addition, we noted that the question "13301 automation error VBA " relates to a problem close to ours and was not solved either

Therefore, what can we do ?

Thank you in advance for your assistance.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: SFTP - VBA/Access - Error automation when creating a Session

Do you have the same versions of .NET installed on those 10 as on the others?
_________________
Martin Prikryl

Reply with quote

gerard_dev
Guest

Re: SFTP - VBA/Access - Error automation when creating a Session

1) All these machines use the framework 4.0.

2) To register the DLL, I use “\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe” if it exists, if not “\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe” if it exists, if not, the user is requested to install the framework 4.0.
Do I have to modify this algorithm or is it correct?

3) Do you have any idea of what means the error automation -2146233321 when creating an instance of the Session class ?
For your information, we had also on some machines the error automation -2146232576 when creating an instance of the Session class, and we discovered that this error was caused by the installation of the DLL on a network drive, and this error disappeared with the DLL installed on a local fixed drive.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: SFTP - VBA/Access - Error automation when creating a Session

gerard_dev wrote:

2) To register the DLL, I use “\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe” if it exists, if not “\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe” if it exists, if not, the user is requested to install the framework 4.0.
Do I have to modify this algorithm or is it correct?
Look good to me, but I'm no .NET expert.

3) Do you have any idea of what means the error automation -2146233321 when creating an instance of the Session class ?
For your information, we had also on some machines the error automation -2146232576 when creating an instance of the Session class, and we discovered that this error was caused by the installation of the DLL on a network drive, and this error disappeared with the DLL installed on a local fixed drive.
I do not know what these mean.
_________________
Martin Prikryl

Reply with quote

aronvanammers
Joined:
Posts:
2

I had this same issue when calling WinSCP through COM on a Win 2012 Server machine.

Googling around showed that the error code 2146232576 / 0x80131700 means the .NET CLR cannot be loaded, a very low-level error: https://stackoverflow.com/a/10513911/81949. Apparently the (right version of) the .NET framework cannot be loaded and the wrapper DLL can't be called.

I was able to solve it as follows by building the WinSCP .NET wrapper from source myself. By default it's targeted to the .NET framework 2.0. I changed the target to 4.5. Using this built version on the target machine and calling it through COM works fine.

Although .NET 4 should be fully backward compatible, in this case probably it isn't.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

aronvanammers wrote:

I was able to solve it as follows by building the WinSCP .NET wrapper from source myself. By default it's targeted to the .NET framework 2.0. I changed the target to 4.5. Using this built version on the target machine and calling it through COM works fine.
Thanks for sharing your solution!
_________________
Martin Prikryl

Reply with quote

San-san
Guest

martin wrote:

aronvanammers wrote:

I was able to solve it as follows by building the WinSCP .NET wrapper from source myself. By default it's targeted to the .NET framework 2.0. I changed the target to 4.5. Using this built version on the target machine and calling it through COM works fine.
Thanks for sharing your solution!

What do you mean "by building the WinSCP .NET wrapper from source myself"?

Reply with quote

Power_ON
Guest

Same problem

Can't register comobject on Windows Server 2012 R2.

I try to build the binary, but get an error:
\libs\puttyvs\PuTTYVS.vcxproj(18,3): error MSB4019: imported project "C:\Microsoft.Cpp.Default.props" not found. Check path <Import> and file on the disk.

1st question: why C:\Microsoft.Cpp.Default.props instead C:\Program Files (x86)\Msbuilt\Microsoft.Cpp\Microsoft.Cpp.Default.props ?
Code from project: <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
This variable $(VCTargetsPath) = C: - why? =)

2nd question: I havn't folder C:\ProgramFiles (x86)\Msbuilt\Microsoft.Cpp - what software should I install to get this ?

README file near build.bat is very scarce (poor, bad).

Reply with quote

Power_ON
Guest

Folder is appears after installing Visual C++ 2015 Build Tools
=)

But now have over 9000 errors like this:
Fatal: Unable to open file 'comboedit.OBJ'
Fatal: Unable to open file 'TB2K.BPI'

and many other

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: Same problem

Power_ON wrote:

Can't register comobject on Windows Server 2012 R2.

I try to build the binary, but get an error:
\libs\puttyvs\PuTTYVS.vcxproj(18,3): error MSB4019: imported project "C:\Microsoft.Cpp.Default.props" not found. Check path <Import> and file on the disk.

1st question: why C:\Microsoft.Cpp.Default.props instead C:\Program Files (x86)\Msbuilt\Microsoft.Cpp\Microsoft.Cpp.Default.props ?
Code from project: <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
This variable $(VCTargetsPath) = C: - why? =)

2nd question: I havn't folder C:\ProgramFiles (x86)\Msbuilt\Microsoft.Cpp - what software should I install to get this ?

README file near build.bat is very scarce (poor, bad).
Why are you trying to build it? What is your purpose?

Anyway, if you want to build the assembly, use dotnet\WinSCPnet.csproj project.
_________________
Martin Prikryl

Reply with quote

Advertisement

You can post new topics in this forum