Fix serialization of delegates without targets
authorStephen Toub <stoub@microsoft.com>
Thu, 18 Aug 2016 18:06:39 +0000 (14:06 -0400)
committerStephen Toub <stoub@microsoft.com>
Thu, 18 Aug 2016 18:06:39 +0000 (14:06 -0400)
A null check is missing when FEATURE_REMOTING is not defined, resulting in an invalid cast exception when deserializing a delegate without a target (e.g. a delegate for a static method).

src/mscorlib/src/System/DelegateSerializationHolder.cs

index 6be712e..a628033 100644 (file)
@@ -221,7 +221,7 @@ namespace System
 #if FEATURE_REMOTING                
                     Object target = de.target != null ? RemotingServices.CheckCast(de.target, targetType) : null;
 #else
-                    if(!targetType.IsInstanceOfType(de.target))
+                    if(de.target != null && !targetType.IsInstanceOfType(de.target))
                         throw new InvalidCastException();
                     Object target=de.target;
 #endif