Skip to content

UnobservedTaskException #11

Description

@LukeOrdelmans

When calling await InitializeConnection() before the PLC is up and running I get a UnobservedTaskException:

Caught "UnobservedTaskException at System.Threading.Tasks.ValueTask+ValueTaskSourceAsTask"
System.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. (Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd.)
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of inner exception stack trace ---

When debugging it seems to originate close to or from awaiting the connection state:

private async Task DoInitializeConnection(bool waitForConnection, CancellationToken token)
{
     ...
     await s7Connector.ConnectionState
                .FirstAsync(c => c == Enums.ConnectionState.Connected)
                .ToTask(token);
     ...
}

note that in order to actually see the exception you'd need to register to the TaskScheduler.UnobservedTaskException event

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions