Cannot use WinSCP.exe

Advertisement

InsanelyOne
Joined:
Posts:
8
Location:
Washington, DC

Cannot use WinSCP.exe

I've got a Windows service I wrote many years ago (at least 7) that leverages WinSCP.dll/WinSCP.exe to transmit files. It has worked fine for all these years until recently. This service runs 24/7 and wakes up every minute to poll an FTP location for files. All of a sudden, at least once a day, sometimes more, it throws the error "Cannot use WinSCP.exe" (the error message contains the correct full path to the .exe). It will continue to throw the error until I restart the service. Then the problem is gone (for some indiscriminate amount of time).

Updating to the most recent version hasn't helped.

My first thought is that the .exe is getting quarantined as malicious but we can find no evidence of that. Plus, that doesn't make sense, since restarting the service fixes the issue.

Theories anyone?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,041
Location:
Prague, Czechia

Re: Cannot use WinSCP.exe

The "Cannot use WinSCP.exe" exception is relatively new. So does it mean that you have updated your service to use the latest version of WinSCP recently?
The exception has an inner exception. What does it say? Can you post a debug log (Session.DebugLogPath)?

Reply with quote

Pradip
Guest

Cannot use WinSCP.exe

Hi martin,

We are getting the same error until we are not to refresh our application pool.

Reply with quote

InsanelyOne
Joined:
Posts:
8
Location:
Washington, DC

Martin,
So it seems I was incorrect about the version. We've been on 5.13.5.8967 since it was released. The error cropped up on November 18th and oddly enough, it occurs roughly every 4–5 days. Looks like it's due again any time now. I'm going to update the service to the latest version (5.19.6). I'll report again in a week or so to see if that fixes the issue.
2022-03-20 18:58:51.383   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-03-16 11:17:20.983   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-03-12 05:12:10.326   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-03-08 08:28:42.626   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-03-04 03:46:37.610   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-28 07:23:04.736   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-24 11:06:54.036   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-19 04:07:49.520   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-15 05:58:25.253   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-11 09:25:42.660   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-07 03:39:05.603   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-02-02 04:47:06.890   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-28 22:15:27.926   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-24 14:23:39.216   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-20 03:27:59.610   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-14 16:37:36.646   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-09 16:36:48.400   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2022-01-05 00:07:44.363   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-31 15:51:41.320   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-26 16:52:33.290   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-22 00:43:29.366   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-17 15:50:13.850   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-10 21:22:01.770   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-06 15:17:22.690   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-12-01 19:30:12.376   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-11-27 02:09:00.553   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-11-22 19:59:36.603   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
2021-11-18 12:31:50.200   Cannot use C:\Program Files\BtgDashboardControl\winscp.exe

Reply with quote

pradip
Guest

Re: Cannot use WinSCP.exe

We are getting the error below.
Error Message: Cannot use C:\Inetpub\winscp.exe
Stack Trace:    at WinSCP.ExeSessionProcess.CheckVersion(String exePath, FileVersionInfo assemblyVersion)
   at WinSCP.ExeSessionProcess..ctor(Session session, Boolean useXmlLog, String additionalArguments)
   at WinSCP.Session.Open(SessionOptions sessionOptions)

Reply with quote

Advertisement

martin
Site Admin
martin avatar

@InsanelyOne: WinSCP 5.13.5 does not throw "Cannot use WinSCP" exception. It would throw a different exception (in the same situation). So something does not match here. You also didn't answer my question about the inner exception. Debug log file (Session.DebugLogPath) would also help. Same for @pradip.

Reply with quote

InsanelyOne
Joined:
Posts:
8
Location:
Washington, DC

@martin: I've updated my code to grab the inner exception. With regard to the version... I was confusing 2 different programs that I have that use WinSCP. The program that is throwing the "Cannot use" error has been running 5.19.5. I just updated it to 5.19.6.

If the trend continues... it will take 4 days for the error to crop up again.

Reply with quote

martin
Site Admin
martin avatar

Re: Cannot use WinSCP.exe

@pradip: It seems that you have set Session.ExecutablePath to point to C:\Windows\TEMP\WinSCP.tmp381D.exe. Why? WinSCP .NET assembly cannot load the binary from that path somehow. Do you also get the error only after some time, like @InsanelyOne? Or do you get it everytime?

Reply with quote

Advertisement

pradip
Guest

Re: Cannot use WinSCP.exe

Yes @martin, this error getting some time not every time.

@martin : First we have set Session.ExecutablePath to point to C:\Windows\TEMP\WinSCP.exe but getting an error "can not use Winscp.exe" so after we have tried to solve this error, We are every time copy and past WinSCP.exe in temp and set temp path
in Session.ExecutablePath.

Reply with quote

martin
Site Admin
martin avatar

Re: Cannot use WinSCP.exe

@pradip: But why do you use C:\Windows\TEMP in the first place? Why don't you use a binary from the location, where your application/code is installed to?

Reply with quote

InsanelyOne
Joined:
Posts:
8
Location:
Washington, DC

Sure enough..after 4 days of running, it threw the error. Unfortunately I don't have a logfile but I do have the inner exception. Hopefully this is helpful.
Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
Cannot retrieve C:\Program Files\BtgDashboardControl\winscp.exe version info

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Cannot use WinSCP.exe

@pradip: So please send debug logs with the standard setup with no hacks like this. With complete exception dumps (with all nested inner exceptions). If that information won't help, based on that I'll try to prepare version with more detailed logging. So please also register, so that I have means to contact you.

Reply with quote

Advertisement

InsanelyOne
Joined:
Posts:
8
Location:
Washington, DC

martin wrote:

@InsanelyOne: Thanks. Actually, the "Cannot retrieve ... version info" should have its own inner exception too.
The inner-inner exception:
Cannot use C:\Program Files\BtgDashboardControl\winscp.exe
Cannot retrieve C:\Program Files\BtgDashboardControl\winscp.exe version info
The specified image file did not contain a resource section

Reply with quote

martin
Site Admin
martin avatar

@InsanelyOne: Thanks. If you disable the version check (Session.DisableVersionCheck = true), would it help or would it fail later elsewhere (and how?)

Once the problem starts occurring, would you be able to run Process Monitor to monitor why loading WinSCP process fails?

Reply with quote

PradipS
Joined:
Posts:
3

Re: Cannot use WinSCP.exe

Hi Martin,

I have attached the latest debug log file for your reference.

We have to install WinSCP NuGet packages 5.19.5.0 in our application and working fine but sometimes get the error "Cannot use Wiscp.exe", until we don't restart our application pool in IIS.
  • debug.log (5 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,041
Location:
Prague, Czechia

Re: Cannot use WinSCP.exe

@PradipS: The log says "Not enough memory resources are available to process this command". Isn't your system running out of memory? Or isn't the application leaking memory? Did you check?

Also as I have suggested to InsanlyOne already: If you disable the version check (Session.DisableVersionCheck = true), would it help or would it fail later elsewhere (and how?)

Reply with quote

martin
Site Admin
martin avatar

Re: So far so good...

@InsanelyOne: Although I've recommended setting Session.DisableVersionCheck = true, checking now what it exactly does, I cannot imagine that it helps. If you remove that setting, would the problem return? Or was it actually fixed by something else (like Windows/.NET update)?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,041
Location:
Prague, Czechia

Re: Cannot use WinSCP.exe

I have added a workaround:
Issue 2075 – Prevent occasional exhaustion of resources while testing WinSCP executable version on repeated use of .NET assembly

I'm sending you an email with a development version of WinSCP to the address you have used to register on this forum. It should not trigger the problem even without setting the Session.DisableVersionCheck = true.

Reply with quote

Advertisement

You can post new topics in this forum