protected static Exception GetInnermostException(Exception ex) { var nextException = ex; while (nextException.InnerException != null) nextException = nextException.InnerException; return nextException; }