public CorValue Invoke(string methodName, CorValue instance, params CorValue[] args) { var allArgs = new List <CorValue>(); if (instance != null) { allArgs.Add(instance); } allArgs.AddRange(args); MDbgFunction func = process.ResolveFunctionNameFromScope(methodName); if (null == func) { throw new Exception(String.Format(CultureInfo.InvariantCulture, "Could not resolve {0}", new Object[] { methodName })); } CorEval eval = process.Threads.Active.CorThread.CreateEval(); // Get Variables ArrayList vars = new ArrayList(); String arg; foreach (var v in allArgs) { if (v is CorGenericValue) { vars.Add(v as CorValue); } else { CorHeapValue hv = v.CastToHeapValue(); if (hv != null) { // we cannot pass directly heap values, we need to pass reference to heap valus CorReferenceValue myref = eval.CreateValue(CorElementType.ELEMENT_TYPE_CLASS, null).CastToReferenceValue(); myref.Value = hv.Address; vars.Add(myref); } else { vars.Add(v); } } } eval.CallFunction(func.CorFunction, (CorValue[])vars.ToArray(typeof(CorValue))); return(GetResult()); }