Fix for issue 5343: Assert Failure: !"Cannot take the address of an uninstantiated...
authorFadi Hanna <fadim@microsoft.com>
Wed, 1 Jun 2016 20:05:45 +0000 (13:05 -0700)
committerFadi Hanna <fadim@microsoft.com>
Wed, 1 Jun 2016 20:05:45 +0000 (13:05 -0700)
The problem was that the delegates code base was not correctly instantiating interface GVMs on target types
(after finding the target method on the target type using slot numbers), and ended up calling uninstantiated
generic method definitions on delegate invokes.

src/vm/comdelegate.cpp

index 57e28030b4759f7e719fcaacfb6bcbf9849e9dd9..b6cab68ff9e27ee3df10788988ee71b2c68d6089 100644 (file)
@@ -2102,11 +2102,25 @@ FCIMPL3(void, COMDelegate::DelegateConstruct, Object* refThisUNSAFE, Object* tar
                                 // <TODO>it looks like we need to pass an ownerType in here.
                                 //  Why can we take a delegate to an interface method anyway?  </TODO>
                                 // 
-                                pMeth = pMTTarg->FindDispatchSlotForInterfaceMD(pMeth).GetMethodDesc();
-                                if (pMeth == NULL)
+                                MethodDesc * pDispatchSlotMD = pMTTarg->FindDispatchSlotForInterfaceMD(pMeth).GetMethodDesc();
+                                if (pDispatchSlotMD == NULL)
                                 {
                                     COMPlusThrow(kArgumentException, W("Arg_DlgtTargMeth"));
                                 }
+
+                                if (pMeth->HasMethodInstantiation())
+                                {
+                                    pMeth = MethodDesc::FindOrCreateAssociatedMethodDesc(
+                                        pDispatchSlotMD,
+                                        pDispatchSlotMD->GetMethodTable(),
+                                        (!pDispatchSlotMD->IsStatic() && pDispatchSlotMD->GetMethodTable()->IsValueType()),
+                                        pMeth->GetMethodInstantiation(),
+                                        FALSE /* allowInstParam */);
+                                }
+                                else
+                                {
+                                    pMeth = pDispatchSlotMD;
+                                }
                             }
                         }
                     }