在包含该行的 finally 块中引发异常response.Close();
try
{
response = (FtpWebResponse)request.GetResponse();
}
catch (System.Net.WebException webEx)
{
FtpWebResponse ftpResponse = (FtpWebResponse)webEx.Response;
if (ftpResponse.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
return false;
}
throw;
}
finally
{
if (response != null)
{
response.Close();
}
}
这是堆栈跟踪:
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.CommandStream.CheckContinuePipeline()
at System.Net.FtpWebRequest.DataStreamClosed(CloseExState closeState)
at System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.FtpDataStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.Net.FtpWebResponse.Close()
at FVC.RequestForStock.Application.RequestForStockDataImportProvider.VerifyDirectoryExist(String serverAddress, String userName, SecureString password) in C:\CoName.RFS.Application\RFSDataImportProvider.cs:line 122
最后调试检查器显示的内容
(如果您无法辨认出文字,请放大图片,例如在 Firefox 中按住 ctrl 并向上滚动鼠标滚轮) 有人可以协助确定异常发生的原因以及如何防止异常发生。 编辑:使用 Microsoft.NET 框架的 v4.0