internal static string RunAjaxMethod(MethodInfo ajaxMethod, object obj, bool useXml) { WebAppContext.AjaxContext = new AjaxContext(); WebAppContext.AjaxContext.ViewName = WebAppContext.FormData["_VIEWNAME_"]; try { object result = ajaxMethod.Invoke(ajaxMethod.IsStatic ? null : obj, CreateParameters(ajaxMethod)); return(useXml ? (string)result : AjaxHelper.GenerateJSONReturnValue(result)); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ExceptionHelper.ResolveTargetInvocationException((TargetInvocationException)ex); } return(useXml ? AjaxHelper.GenerateXmlError(ex.Message) : AjaxHelper.GenerateJSONError(ex.Message)); } }