<p>This is about when a .NET remoting exception is thrown. If you take a look at MSDN, it will mention that a remoting exception is thrown when something goes wrong with remoting. If my server is not running, I get a socket exception which is fine.</p>
<p>What I am trying to figure out is: does getting a remoting exception indicate for sure that my server is up and running? If yes, that would solve the problem. If not: Is there a way to figure out if the remoting exception originated on the client side or the server side?</p>
<h3>Update:</h3>
<p>The problem I am trying to solve is that the server is down initially and then client sends some message to the server. Now I get a socket exception saying &quot;No connection could be made...&quot; which is fine.</p>
<p>There is a thread that is sending messages to the server at regular intervals to see if the server is available. Now, the server comes up, and at that point, you could get the response which is fine or you could get some exception and most probably it will be a remote exception. So, what I am trying to ask is that: in case I don't get a message and I get a remote exception is there a chance that the server is up and running and I am still getting this exception?</p>
<p>All I am doing is just calling a method on the remote object that does nothing and returns. If there is no exception then I am good. Now, if there is a remoting exception and if I knew the remoting exception occurred on the server then I know in spite getting the exception, I am connected to the server.</p>

[{'answer_id': 73938, 'author': 'sumek', 'author_id': 11439, 'author_profile': 'https://Stackoverflow.com/users/11439', 'pm_score': 0, 'selected': False, 'text': '<p>Try assuring that you send the correct message and the messages received by the server are also correct, e.g. using assertions (it is called Design by Contract).\nIf you have such possibility, try debugging the server side and client side at the same time. (running two VS instances at the same time)</p>\n'}, {'answer_id': 74099, 'author': 'Rikalous', 'author_id': 4271, 'author_profile': 'https://Stackoverflow.com/users/4271', 'pm_score': 0, 'selected': False, 'text': "<p>I haven't got access to the source code of my last remoting application, but as far as I can remember we couldn't figure out a way of knowing for definite if the server was up from any of the exceptions we got.<br>\nWe did check to see if the network was present and warned the user if not (a method on the Environment class I think).</p>\n"}, {'answer_id': 74130, 'author': 'Thomee', 'author_id': 12825, 'author_profile': 'https://Stackoverflow.com/users/12825', 'pm_score': 2, 'selected': True, 'text': '<p>Getting a remoting exception does not guarantee that your server is up and running.  If something else happens to be running and listening on that port, the connection will succeed, and you will not get a socket exception.  What happens in this case depends on how the application which actually got your connection behaves, but it will probably wind up generating a remoting exception in your client.</p>\n\n<p>It would take a bit more investigation to verify this, but I believe the remoting exception indicates a problem in the communications between the client and the server, so there isn\'t a "client side" or "server side" that generated it.  It means that the two weren\'t talking happily and it could have been caused by either one.</p>\n'}, {'answer_id': 74382, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 0, 'selected': False, 'text': '<p>If the server side application logic threw an exception, it should be able to marshal over to the client to let it know what happened. You can test this by deliberately throwing an exception in one of the remote object\'s methods. Then call that particular method from the client side expecting an exception:</p>\n\n<pre><code>HttpChannel channel = new HttpChannel();\nChannelServices.RegisterChannel(channel);\n\nIMyRemoteObject obj = (IMyRemoteObject) Activator.GetObject(\n    typeof(IMyRemoteObject),\n    "http://localhost:1234/MyRemoteObject.soap");\nConsole.WriteLine("Client.Main(): Reference to rem.obj. acquired");\n    int tmp = obj.GetValue();\n    Console.WriteLine("Client.Main(): Original server side value: {0}",tmp);\nConsole.WriteLine("Client.Main(): Will set value to 42");\n\ntry\n{\n    // This method will throw an ApplicationException in the server-side code.\n    obj.SetValue(42);\n}\ncatch (Exception ex)\n{\n    Console.WriteLine("=====");\n    Console.WriteLine("Exception type: " + ex.GetType().ToString());\n    Console.WriteLine("Message: " + ex.Message);\n    Console.WriteLine("Source: " + ex.Source);\n    Console.WriteLine("Stack trace: " + ex.StackTrace);\n    Console.WriteLine("=====");\n}\n</code></pre>\n\n<p>You can expect an exception received like this</p>\n\n<pre><code>=====\nException type: System.ApplicationException\nMessage: testing\nSource: Server\nStack trace:\nServer stack trace:\n   at Server.MyRemoteObject.SetValue(Int32 newval) in i:\\projects\\remoting.net\\ch03\\01_singlecallobjects\\server\\server.cs:line 27\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]&amp; outArgs)\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)\n\nException rethrown at [0]:\n   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\n   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)\n   at General.IMyRemoteObject.SetValue(Int32 newval)\n   at Client.Client.Main(String[] args) in i:\\projects\\remoting.net\\ch03\\01_singlecallobjects\\client\\client.cs:line 29\n=====\n</code></pre>\n\n<p>It should tell you the Source is at the server, with a server-side stack trace.</p>\n'}, {'answer_id': 74528, 'author': 'Steve Dinn', 'author_id': 12338, 'author_profile': 'https://Stackoverflow.com/users/12338', 'pm_score': 2, 'selected': False, 'text': '<p>If you are intending to use custom exception types to be thrown across the remoting boundray, be sure to mark these types as "[Serializable]".  I can\'t remember the exact error message, but it perplexed me for the better part of a day the first time I saw it.</p>\n\n<p>Also, just a tip, TargetInvocationException often has the REAL exception embedded in its InnerException property.  There is nothing more useless than "An exception was thrown by the target of an invocation."</p>\n'}, {'answer_id': 74630, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 0, 'selected': False, 'text': '<p>Ok now that you have put it that way, I assume you are use TCP for remoting, for if it was via HTTP, it would be a WebException thrown when failing to connect to the (TCP network port) server. When the server has not launched the application program to register the channel on that designated TCP port, you will get a SocketException. After all, the server is not listening/responding to that port, how can the client ever make a socket connection?</p>\n\n<p>But, if you get a RemotingException it need <em>not</em> necessarily mean the server has its proper Remoting application running fine. You could test by connecting to a wrong URI on a wrong port, like port 80 (IIS).</p>\n\n<pre><code>IMyRemoteObject obj = (IMyRemoteObject) Activator.GetObject(\n    typeof(IMyRemoteObject),\n    "tcp://localhost:80/MyRemoteObject.rem");\n</code></pre>\n\n<p>That would result in a RemotingException because while the client can make a TCP connection to port 80, it is IIS responding to the call and not the Remoting app; IIS cannot handle remoting calls directly. Having said that, a RemotingException can also jolly mean a problem at the client side. This blog article may help you understand better.</p>\n\n<p><a href="http://www.cookcomputing.com/blog/archives/000308.html" rel="nofollow noreferrer">http://www.cookcomputing.com/blog/archives/000308.html</a></p>\n'}]
['https://Stackoverflow.com/questions/73825', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']