System.InvalidOperationException: Element session@0 already read to the end

Advertisement

vbdotnetdeveloper
Joined:
Posts:
2

System.InvalidOperationException: Element session@0 already read to the end

Hello,
I'm using WinSCP .NET assembly version 6.3.5.

We have a process to download the images from FTP server, it loops through files need to be downloaded, if the file does not exist on the server, it moves to next file. We noticed that when 10-12 files not found in sequence, WinSCP throwing exception with message (from SessionLog.txt) file "You are being kicked off the server. Goodbye ABC from IP Address.".

.NET exception it shows is "System.InvalidOperationException: Element session@0 already read to the end".

Here code snippet
Transfer.cs file:
var sessionOptions = new SessionOptions
{
    Protocol = p,
    PortNumber = port,
    FtpSecure = (FtpSecure)ftpMode,
    FtpMode = FtpMode.Passive,
    TimeoutInMilliseconds = Int32.MaxValue,//Insanely large number...because I need it
    HostName = server,
    UserName = userName,
    Password = password
};
if (p != Protocol.Ftp)
    sessionOptions.SshHostKeyFingerprint = hostKey;
 
_session = new Session();
_session.Open(sessionOptions);
DonwloadImages.cs
using (var ftp = new Transfer(Protocol.Ftp))
{
    foreach (var fld in imageDirLst)
    {
        if (!ftp.DownloadFile(RootFolder + fld.FileFolder + "/", fld.Name, locDest, 0))
        {
            log.Error("Failed to download file");
        }
    }
}

Reply with quote

Advertisement

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

Re: System.InvalidOperationException: Element session@0 already read to the end

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

martin
Site Admin
martin avatar

Re: System.InvalidOperationException: Element session@0 already read to the end

What do you want to solve? We cannot know why the server disconnects you. For that you need to contact the server administrator.
If you want to solve the strange WinSCP error and have WinSCP handle the disconnect more gracefully, please post debug log – Session.,DebugLogPath.

Reply with quote

Advertisement

You can post new topics in this forum