TransferOperationResult disposed before I can serialize it.
I have a method that performs an FTP put and returns results to the caller in the form of a
The method doing the put is pretty straightforward:
In the calling routine, I'm serializing result to JSON. Most of the time, this works great, but every once in a while, I see "System.InvalidOperationException: Object is disposed" when writing result to JSON.
With result declared outside the using block, I didn't think result was going to be disposed, but it seems to be doing just that. Does anyone see anything *obvious* I'm doing wrong?
TransferOperationResult
object. The intent is to write these results as a JSON doc and use success & failure counts to evaluate overall success.
The method doing the put is pretty straightforward:
TransferOperationResult? result = null; try { SessionOptions sessionOptions = new SessionOptions { ... }; using (Session session = new Session()) { // Connect session.Open(sessionOptions); // Upload files TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; transferOptions.OverwriteMode = OverwriteMode.Overwrite; transferOptions.ResumeSupport.State = TransferResumeSupportState.Off; result = session.PutFiles(fromPath, toPath, false, transferOptions); } } catch (Exception ex) { _logger.LogError("Exception in ftp CopyToDestination: {0}", ex.ToString()); } return result;
With result declared outside the using block, I didn't think result was going to be disposed, but it seems to be doing just that. Does anyone see anything *obvious* I'm doing wrong?