@@ -457,13 +457,14 @@ public void HandleMainLoopException(ShutdownEventArgs reason)
457457 {
458458 if ( ! SetCloseReason ( reason ) )
459459 {
460- LogCloseError ( "Unexpected Main Loop Exception while closing: "
461- + reason , new Exception ( reason . ToString ( ) ) ) ;
460+ LogCloseError ( $ "Unexpected Main Loop Exception while closing: { reason } ", reason . Exception ) ;
462461 return ;
463462 }
464463
464+ _model0 . MaybeSetConnectionStartException ( reason . Exception ) ;
465+
465466 OnShutdown ( ) ;
466- LogCloseError ( $ "Unexpected connection closure: { reason } ", new Exception ( reason . ToString ( ) ) ) ;
467+ LogCloseError ( $ "Unexpected connection closure: { reason } ", reason . Exception ) ;
467468 }
468469
469470 public bool HardProtocolExceptionHandler ( HardProtocolException hpe )
@@ -540,22 +541,33 @@ public void MainLoop()
540541 catch ( EndOfStreamException eose )
541542 {
542543 // Possible heartbeat exception
543- HandleMainLoopException ( new ShutdownEventArgs (
544- ShutdownInitiator . Library ,
545- 0 ,
546- "End of stream" ,
547- eose ) ) ;
544+ var ea = new ShutdownEventArgs ( ShutdownInitiator . Library ,
545+ 0 , "End of stream" ,
546+ cause : null , exception : eose ) ;
547+ HandleMainLoopException ( ea ) ;
548548 }
549549 catch ( HardProtocolException hpe )
550550 {
551551 shutdownCleanly = HardProtocolExceptionHandler ( hpe ) ;
552552 }
553+ catch ( FileLoadException fileLoadException )
554+ {
555+ /*
556+ * https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1434
557+ * Ensure that these exceptions eventually make it to application code
558+ */
559+ var ea = new ShutdownEventArgs ( ShutdownInitiator . Library ,
560+ Constants . InternalError , fileLoadException . Message ,
561+ cause : null , exception : fileLoadException ) ;
562+ HandleMainLoopException ( ea ) ;
563+ }
553564 catch ( Exception ex )
554565 {
555- HandleMainLoopException ( new ShutdownEventArgs ( ShutdownInitiator . Library ,
566+ var ea = new ShutdownEventArgs ( ShutdownInitiator . Library ,
556567 Constants . InternalError ,
557- "Unexpected Exception" ,
558- ex ) ) ;
568+ $ "Unexpected Exception: { ex . Message } ",
569+ cause : null , exception : ex ) ;
570+ HandleMainLoopException ( ea ) ;
559571 }
560572
561573 // If allowed for clean shutdown, run main loop until the
@@ -1104,7 +1116,8 @@ private void StartAndTune()
11041116
11051117 if ( connectionStart == null )
11061118 {
1107- throw new IOException ( "connection.start was never received, likely due to a network timeout" ) ;
1119+ const string msg = "connection.start was never received, likely due to a network timeout" ;
1120+ throw new IOException ( msg , _model0 . ConnectionStartException ) ;
11081121 }
11091122
11101123 ServerProperties = connectionStart . m_serverProperties ;
0 commit comments