Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application terminates without exception when attempting to use ConnectAsync #262

Closed
WaterskiScoring opened this issue Feb 3, 2022 · 4 comments

Comments

@WaterskiScoring
Copy link

WaterskiScoring commented Feb 3, 2022

I have created a C# project using SocketIO 3.0.5 as a handler interface with a socketIo server 2.3.0. I have run this project stand alone and all functionality works as desired. However, when I include this project with a large C# application that I have that I want to interface with my SocketIO handler the application simply terminates a few seconds after issuing the ConnectAsync message. The OnConnected callback doesn't seem to be reacting so I'm assume it is failing before the connection is complete. I saw a similar issue from last year to this but the one differences is that I do run successfully stand alone but not when included with my larger application. I am suspecting a conflict with some other dependency but I haven't been able to isolate the conflict. Wondering if there are any suggestions of what my issue might be.

Including a snippet of my code:

		public static void startWscListener( String sanctionNum, String eventSubId ) {
			String curMethodName = "Listener: startWscListener: ";
			myLastConnectResponse = "";
			mySanctionNum = sanctionNum;
			myEventSubId = eventSubId;
			Log.WriteFile( String.Format( "{0}start in progress, {1}/{2}", curMethodName, mySanctionNum, myEventSubId ) );

			try {
				socketClient = new SocketIO( ConnectDialog.WscWebLocation, new SocketIOOptions {
					Transport = TransportProtocol.WebSocket
					, Reconnection = true
					, ReconnectionDelay = 1000
					, EIO = 3
				} );

				clientListeners();
				
				Log.WriteFile( String.Format( "{0}ClientListeners started, begin monitoring for messages from {1}", curMethodName, ConnectDialog.WscWebLocation ) );
				socketClient.ConnectAsync();
				Log.WriteFile( String.Format( "{0}ConnectAsync", curMethodName ) );

			} catch ( Exception ex ) {
				String curMsg = String.Format( "{0}Exception encounter {1}: {2}", curMethodName, ex.Message, ex.StackTrace );
				Log.WriteFile( curMsg );

				ConnectDialog.WscWebLocation = "";
				myLastConnectResponse = "";
				myEventSubId = "";

				MessageBox.Show( curMsg );
			}
		}

		private static void clientListeners() {
			String curMethodName = "Listener: clientListeners: ";
			Log.WriteFile( String.Format( "{0}", curMethodName ) );

			try {
				socketClient.OnConnected += handleSocketOnConnected;

				//socketClient.OnPing += handleSocketOnPing;

				//socketClient.OnPong += handleSocketOnPong;

				socketClient.OnDisconnected += handleSocketOnDisconnected;

				socketClient.OnReconnectAttempt += handleSocketOnReconnecting;

				socketClient.On( "connect_confirm", ( response ) => {
					handleWscConnectConfirm( "connect_confirm", response.GetValue<string>() );
				} );

				socketClient.OnAny( ( name, response ) => {
					Log.WriteFile( String.Format( "{0}Default SocketClient callback handler: Name: {1}, Data: {2}", curMethodName, name, response == null ? "Null" : response.GetValue<string>() ) );
				} );

				socketClient.On( "connectedapplication_check", ( response ) => {
					handleConnectHeartBeat( "connectedapplication_check", response.GetValue<string>() );
				} );

				socketClient.On( "boat_times", response => {
					HelperFunctions.addMsgListenQueue( "boat_times", response.GetValue<string>() );
					Log.WriteFile( String.Format( "{0}boat_times {1}", curMethodName, response.GetValue<string>() ) );
				} );

				socketClient.On( "boatpath_data", ( response ) => {
					HelperFunctions.addMsgListenQueue( "boatpath_data", response.GetValue<string>() );
					Log.WriteFile( String.Format( "{0}boatpath_data {1}", curMethodName, response.GetValue<string>() ) );
				} );

				socketClient.On( "scoring_result", ( response ) => {
					HelperFunctions.addMsgListenQueue( "scoring_result", response.GetValue<string>() );
					Log.WriteFile( String.Format( "{0}scoring_result {1}", curMethodName, response.GetValue<string>() ) );
				} );

				socketClient.On( "trickscoring_detail", ( response ) => {
					HelperFunctions.addMsgListenQueue( "trickscoring_detail", response.GetValue<string>() );
					Log.WriteFile( String.Format( "{0}trickscoring_detail {1}", curMethodName, response.GetValue<string>() ) );
				} );

				socketClient.On( "jumpmeasurement_score", ( response ) => {
					HelperFunctions.addMsgListenQueue( "jumpmeasurement_score", response.GetValue<string>() );
					Log.WriteFile( String.Format( "{0}jumpmeasurement_score {1}", curMethodName, response.GetValue<string>() ) );
				} );

				socketClient.On( "status_response", ( response ) => {
					checkConnectStatus( response.GetValue<string>() );
				} );

			} catch ( Exception ex ) {
				String curMsg = String.Format( "{0}Exception encounter {1}", curMethodName, ex.Message );
				Log.WriteFile( curMsg );
				MessageBox.Show( curMsg );
			}
		}
@doghappy
Copy link
Owner

doghappy commented Feb 8, 2022

Perhaps, you need to use fiddler to debug and see what is the difference between 'project stand alone' and 'large C# application'.

@WaterskiScoring
Copy link
Author

I noticed that suggestion in another issue so I did that this afternoon. The issue appears to be what is happening with handling the connection response. Based on that I have been comparing the DLL libraries being included in the 2 builds. The 2 projects seem to have some differences in the DLL/XML files for the Newtonsoft.Json component and the System.Text.Json component. Even thou NuGet is indicating both projects are including the same version but the files seem slightly different. I overlaid the files from the stand alone project on the larger project and that did seem to fix the problem. I'm trying to isolate exactly which file(s) are causing the issue. In any event SocketIOClient seems to be sensitive to the versions of one or more of these files. I'm a bit perplexed how the NuGet Package Manager for one project is getting different files than the other project. I would say you can probably close this issue is that it doesn't seem to be an issue with SocketIOClient but with the included dependencies. Let me know If you are interested in knowing exactly which file versions are causing the issue once I isolate it.

@WaterskiScoring
Copy link
Author

WaterskiScoring commented Feb 8, 2022

In case anyone else runs into a similar issue I have isolated my issue. My larger package was using NuGet to include System.Text.Json version 6.0.1 and with this package the response from the ConnectAsync seemed to be causing the executable to terminate without throwing an exception. When I downgraded this package to version 6.0.0 the ConnectAsync response was handled without issue.

Just for information version 6.0.0 was published on 11/8/2021, version 6.0.1 was published on 12/14/2021. I noticed today that a version 6.0.2 was showing as available but I haven't yet installed that to test.

I notice that 6.0.2 was published today 2/8/2022 so I decided to give it a try. Like 6.0.1 it didn't work with SocketIOClient. Therefore I have reverted back to 6.0.0 to allow the connection to work successfully

@doghappy
Copy link
Owner

doghappy commented Feb 9, 2022

In the next release I will update all dependencies to the latest version

<PackageReference Include="System.Text.Json" Version="6.0.0" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants