Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

rh

Search AppDomain.Current.BaseDirectory for WinSCP.exe

When publishing a .NET app as a single file (<PublishSingleFile>true</PublishSingleFile>), WinSCP.exe is not found even if it sits beside the published exe:
 WinSCP.SessionLocalException: The winscp.exe executable was not found at location of the assembly WinSCPnet (), nor the entry assembly Memphis (), nor in an installation path. You may use Session.ExecutablePath property to explicitly set path to winscp.exe.

   at WinSCP.ExeSessionProcess.FindExecutable(Session session)
   at WinSCP.Session.GetExecutablePath()
   at WinSCP.Session.get_ExecutablePath()
   at WinSCP.ExeSessionProcess.GetExecutablePath()
   at WinSCP.ExeSessionProcess..ctor(Session session, Boolean useXmlLog, String additionalArguments)
   at WinSCP.ExeSessionProcess.CreateForSession(Session session)
   at WinSCP.Session.Open(SessionOptions sessionOptions)

The fix is to add
session.ExecutablePath =
    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WinSCP.exe");

This is a request to automatically search AppDomain.CurrentDomain.BaseDirectory (or AppContext.BaseDirectory, but that is not available on net40).

P.S. A semi-related issue, setting session.DebugLogPath results in an error:
System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.

   at System.Reflection.RuntimeAssembly.get_CodeBase()
   at WinSCP.Logger.WriteEnvironmentInfo()
   at WinSCP.Logger.SetLogPath(String value)
   at WinSCP.Logger.set_LogPath(String value)
   at WinSCP.Session.set_DebugLogPath(String value)