/// <summary> /// This performs a more diligent Import-like operation. The standard Import method can sometimes fail unpredictably when generics are involved. /// Note that it's possible yourMethodRef will be mutated, so don't use it. /// </summary> /// <param name="yourMethodRef">A reference to your method.</param> /// <returns></returns> private MethodReference ManualImportMethod(MethodReference yourMethodRef) { //the following is required due to a workaround. var newRef = yourMethodRef.IsGenericInstance ? yourMethodRef : yourMethodRef.MakeReference(); foreach (var param in newRef.Parameters) { if (param.ParameterType.IsVarOrMVar()) continue; //also workaround, though I'm not sure if we need this anymore. param.ParameterType = FixTypeReference(param.ParameterType); } if (!newRef.ReturnType.IsVarOrMVar()) { newRef.ReturnType = FixTypeReference(yourMethodRef.ReturnType); } return newRef; }