Comments: ** Comment from web user: jsf75 **
Hi all,
My real problem is that a exception in sshnet makes my process been killed !
the call stack :
AggregateException := A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
at System.Threading.Tasks.TaskExceptionHolder.Finalize()
NullReferenceException := Object reference not set to an instance of an object.
at Renci.SshNet.Sftp.SubsystemSession.RaiseError(Exception error) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\SubsystemSession.cs:line 138
at Renci.SshNet.Sftp.SubsystemSession.Session_ErrorOccured(Object sender, ExceptionEventArgs e) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\SubsystemSession.cs:line 194
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Renci.SshNet.Session.RaiseError(Exception exp) in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 1934
at Renci.SshNet.Session.MessageListener() in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 1597
at Renci.SshNet.Session.<Connect>b__4() in C:\Users\jsf\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 529
at System.Threading.Tasks.Task.Execute()
In my case, I have message = null in Session.cs, line 1584.
extract of session.Cs :
private void MessageListener()
{
try
{
while (this._socket != null && this._socket.Connected)
{
var __message__ = this.ReceiveMessage();
if (message == null)
{
throw new NullReferenceException("The 'message' variable cannot be null");
}
this.HandleMessageCore(message);
}
}
catch (Exception exp)
{
this.__RaiseError__(exp);
}
}
so, since MessageListener is called from Session line 529 :
this.__ExecuteThread__(() =>
{
try
{
this.__MessageListener__();
}
finally
{
this._messageListenerCompleted.Set();
}
});
-> MessageListener runs in an other thread... and receive a null message, which implies RaiseError Method, which uses
protected void RaiseError(Exception error)
{
this._exception = error;
__this._errorOccuredWaitHandle.Set();__
if (this.ErrorOccurred != null)
{
this.ErrorOccurred(this, new ExceptionEventArgs(error));
}
}
-> and it seems that session has been disposed before RaiseError() has been called, which leads to a null reference exception in line 138 of subsystemSession.cs
So, this uncatched exception makes the process stop (since this thread is not managed for exception handling) :
http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.unobservedtaskexception.aspx
I'm going to try to register to the event as you can see here :
http://stackoverflow.com/questions/8803107/task-and-exception-silence
I will let you know...