Merge pull request #2216 from akoeplinger/fix-array-sort
[mono.git] / mcs / class / corlib / System / WeakReference.cs
index b39e52c9e118b2fd9893cebb3b73b7606b20db4d..7ba2a7abd4c24423c204ddc4c898fa2a7afeee7f 100644 (file)
@@ -34,6 +34,7 @@ using System.Runtime.InteropServices;
 namespace System
 {
        [Serializable]
+       [ComVisible (true)]
        public class WeakReference : ISerializable
        {
                //Fields
@@ -53,6 +54,11 @@ namespace System
                }
 
                //Constructors
+#if NET_2_1
+               protected WeakReference ()
+               {
+               }
+#endif
                public WeakReference (object target)
                        : this (target, false)
                {
@@ -79,13 +85,16 @@ namespace System
                public virtual bool IsAlive {
                        get {
                                //Target property takes care of the exception
-                               return (Target != null);                
+                               return (Target != null);
                        }
                }
 
                public virtual object Target {
                        get {
-                               //Exception is thrown by gcHandle's Target
+                               // This shouldn't throw an exception after finalization
+                               // http://blogs.msdn.com/b/yunjin/archive/2005/08/31/458231.aspx
+                               if (!gcHandle.IsAllocated)
+                                       return null;
                                return gcHandle.Target;
                        }
                        set