How to handle XcoCommunicationException

Feb 4, 2010 at 7:50 AM


I deal recently with AppSpace and have a question. How I can handle XcoCommunicationException.

Here is my example code:

Using mvarClient = New XcoAppSpace(clientSpaceConfig)
            Dim serviceSpaceConfig As String = String.Format("{0}:{1}", My.Settings.Service, My.Settings.TCPPort)
            mvarFileService = mvarClient.ConnectWorker(Of PServiceFiles)(serviceSpaceConfig)

            Arbiter.Activate(mvarClient.DefaultDispatcherQueue, Arbiter.Receive(True, mvarResponse, AddressOf OnFilesReceived))
        End Using

A small example is very helpful.



Feb 4, 2010 at 11:45 AM

Where does the exception get thrown in your small sample?

Why is it difficult for you to catch it?



Feb 4, 2010 at 12:51 PM

It happens here

mvarClient.ConnectWorker(Of PServiceFiles)(serviceSpaceConfig)

Because the connection is built up in a WorkerThread and not in the main thread.

I have tried to handle it in a Try-Catsch block. Unfortunately, unsuccessfully.


Feb 8, 2010 at 10:31 AM


Unfortunately I don't understand the problem exactly. If The ConnectWorker call throws an exception, it should normally be no problem to catch it like you would normally do:

catch (XcoCommunicationException ex)
   do some errorhandling...
Does it not work for you this way? The exception should always be thrown in the same thread where ConnectWorker is called.
Feb 8, 2010 at 1:28 PM

Hi Thomas,

You are right, I have also made this.

Public Sub New()

' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. Dim clientSpaceConfig As String = String.Format("tcp.port={0}", 0)

Using mvarClient = New XcoAppSpace(clientSpaceConfig)
Dim serviceSpaceConfig As String = String.Format("{0}:{1}", My.Settings.Service, My.Settings.TCPPort)
Try mvarFileService = mvarClient.ConnectWorker(Of PServiceFiles)(serviceSpaceConfig) Catch ex As XcoAppSpaces.Contracts.Exceptions.XcoCommunicationException
MessageBox.Show(ex.Message, "Connection not possibly", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Try End Using End Sub

I get error in this line

mvarFileService = mvarClient.ConnectWorker(Of PServiceFiles)(serviceSpaceConfig)

And here is the error message, I heoffe you understands in German

XcoAppSpaces.Contracts.Exceptions.XcoCommunicationException wurde nicht von Benutzercode behandelt.
  Message="Error sending Message to Address \"pchh0184:9010\" : Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte"
       bei XcoAppSpaces.Transport.Sockets.XcoTCPTransportService.Send(XcoMessage msg) in d:\Development\Uni\XcoAppSpaces Codeplex\source.implementation\XcoAppSpaces.Transport.Sockets\XcoAppSpaces.Transport.Sockets\XcoTCPTransportService.cs:Zeile 242.
       bei XcoAppSpaces.Core.Communication.InternalConnector.Send(String remoteAddress, String commServiceName, CausalityContext context, RemoteMessage data) in d:\Development\Uni\XcoAppSpaces Codeplex\source.implementation\XcoAppSpaces.Core.Communication\XcoAppSpaces.Core.Communication\internal\InternalConnector.cs:Zeile 187.
       bei XcoAppSpaces.Core.Communication.InternalConnector.SendMessage(MessageToSend message) in d:\Development\Uni\XcoAppSpaces Codeplex\source.implementation\XcoAppSpaces.Core.Communication\XcoAppSpaces.Core.Communication\internal\InternalConnector.cs:Zeile 167.
       bei Microsoft.Ccr.Core.Task`1.Execute()
       bei Microsoft.Ccr.Core.TaskExecutionWorker.ExecuteTaskHelper(ITask currentTask)
       bei Microsoft.Ccr.Core.TaskExecutionWorker.ExecuteTask(ITask& currentTask, DispatcherQueue p, Boolean bypassExecute)
       bei Microsoft.Ccr.Core.TaskExecutionWorker.ExecutionLoop()

Thank you for the help


Feb 8, 2010 at 5:31 PM


You get this Exception when the server space cannot be reached. This is normally the case when either the other space has not been started correctly, or when there is something else blocking the connection, like a firewall.

Best check if your server and client applications are both running at the same time, and if the firewall is letting through your communication.

Hope I could help you!


Feb 8, 2010 at 8:19 PM
Edited Feb 8, 2010 at 8:19 PM

Hallo Thomas,

thanks for your answer.

This is known to me. I would like to spend with pleasure an error message if the service is not accessible. The Try Catch block does not reach with me. What do I make wrong?


Feb 9, 2010 at 11:59 AM

Hmmm. I don't think that the ConnectWorker call really throws the exception. When I try your example (and don't have a running server space), I'm getting a comepletely different StackTrace than you are. Could it be that the exception is thrown at the server side?
This would explain why the exception is thrown whithin the CCR. If this is the case, try to continue the application when the exception is thrown, and ConnectWorker will throw an exception a few seconds later (Unfortunately when debugging, exceptions thrown within
code that is executed by the ccr will pop up because they are not caught by your code but the by CCR code; but you can just jump over such errors and your application will continue working).

Another thing that can typically cause problems in such small examples is that the XcoAppSpace Instance is closed too soon because it is automatically disposed at the end of the using statement. To prevent this, you can add a Thread.Sleep
or something before the end of the using statement to keep the XcoAppSpace online for a short while.