Author: andrews
Date: 2006-11-23 13:00:10 -0500 (Thu, 23 Nov 2006)
New Revision: 68406

Modified:
   trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
Log:
Workardound non-serializable HttpException


Modified: trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs        
2006-11-23 16:32:45 UTC (rev 68405)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs        
2006-11-23 18:00:10 UTC (rev 68406)
@@ -10,7 +10,9 @@
 using System.Collections;
 using System.Runtime.Remoting.Messaging;
 using System.Reflection;
-using System.Threading;
+using System.Threading;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
 
 namespace MonoTests.SystemWeb.Framework
 {
@@ -45,6 +47,11 @@
 
                private static void RethrowException (Exception inner)
                {
+                       Exception serializableInner = FindSerializableInner 
(inner);
+                       if (serializableInner != inner) {
+                               throw new Exception ("Cannot serialize 
exception of type " + inner.GetType ().Name,
+                                       serializableInner);
+                       }
                        Exception outer;
                        try { //Try create a similar exception and keep the 
inner intact
                                outer = (Exception) Activator.CreateInstance 
(inner.GetType (),
@@ -56,6 +63,29 @@
                        throw outer;
                }
 
+               private static Exception FindSerializableInner (Exception inner)
+               {
+                       //FIXME: what can be a less expansive, but equally 
reliable
+                       //check that exception can pass remoting?
+                       Exception ex = inner;
+                       Exception mostInner = null;
+                       while (ex != null) {
+                               try {
+                                       BinaryFormatter f = new BinaryFormatter 
();
+                                       f.Serialize (new MemoryStream (), ex);
+                                       //serialization succeeded, return it
+                                       return ex;
+                               }
+                               catch (SerializationException) {
+                                       mostInner = ex;
+                                       ex = ex.InnerException;
+                               }
+                       }
+                       //no inner exceptions remain, create one with message 
and stack of the most inner
+                       ex = new Exception (mostInner.Message + " Call stack: " 
+ mostInner.StackTrace);
+                       return ex;
+               }
+
                private static HttpWorkerRequest GetMyWorkerRequest ()
                {
                        IServiceProvider isp = HttpContext.Current as 
IServiceProvider;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to