Open ALSULTAN opened 1 month ago
System.AggregateException: TaskExceptionHolder_UnhandledException (Operation canceled)
---> System.Net.Sockets.SocketException (89): Operation canceled
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 )
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Net.Sockets.TcpClient.CompleteConnectAsync(Task )
Exception_EndOfInnerExceptionStack
Not sure what you meant, but the code you linked is inside a try catch
catch (Exception e)
{
Logging.Logger?.LogError(e, "[{Function}]:[{PrinterName}] Unable to connect to printer.", $"{this}.{MethodBase.GetCurrentMethod().Name}", _settings.PrinterName);
client.Close();
throw;
}
You can check the logs for the error details, but sounds like you are unable to connect to your printer...
Actually, there is a throw
on catch
statement
and the method RunTask
is throwing another ThrowIfCancellationRequested
hope this helps. anyone who knows the code well can see the exception is propagating to the caller application
Yep, the throw
is on purpose, so the exception is not swallowed by the library, and the lib user can act upon it, and actually know there was a connection error, otherwise it would just silently fail for you when such a lack of connection happens.
If you have a better proposal of how to handle that, you are welcome to open a PR as this is an open source project :)
https://github.com/lukevp/ESC-POS-.NET/blame/ac185fc58bf9e5ad937750b8fc92c02baf344cc9/ESCPOS_NET/Printers/ImmediateNetworkPrinter.cs#L49