Integration error: Cannot access disposed object Follow
When running a socket integration or using a network location as your scan directory, you may encounter an error message like this within the logs:
ERROR|Integration [connection name] failed to send message. Details: 'Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.'
For FTP integrations, it may indicate that the FTP connection was temporarily refused. Increasing the polling time by a few seconds often relieves this issue.
For Socket integrations, a symptom of this error message may be completely skipping a label print. For very busy socket integrations, this error message likely will appear in the middle of a busy stream of socket requests or sometimes when the socket is idling.
In busy integrations, the socket doesn't always close when set to "Port Becomes Idle", so new requests are essentially smacking against an open door and pouring through without being processed.
To fix this, we need to control how and when BarTender opens and closes the socket. In the "Input Data" section of your integration, you can force the Integration to close the socket after it reads a certain sequence of characters.
The most straightforward means to do this is to search for the closing tag in the BTXML and force close the socket right afterwards. This method is shown in the steps for the Print Document Using BTXML over a Network Socket tutorial.
In the Input Data section of the Integration, change the settings as follows:
This tells the Integration to shut off the socket right after receiving </XMLScript>. The checkbox ensures that the closing tag is preserved within the input data so the BTXML script processes correctly.
In some cases, Version 1 is simply not enough. The integration never closes the socket or the stream is terminated too quickly and the data is cut off. Other cases include the sender expecting a specific response to close the socket. In this case, in addition to forcing the data stream to end after a certain character sequence, you can force the connection to close on BarTender's side using a "Send to Network Socket" action.
This action will force a response right after it is done receiving data then terminate the connection.