Actions with retries

private static void DoWithRetries(Action action, 
                                  int tryCount = 3, 
                                  string addMessage = "")
{
    bool success = false;
    int tryIndex = 0;

    do
    {
        try
        {
            action();
            success = true;
        }
        catch (Exception ex)
        {
            tryIndex++;

            // any sort of logging
            Console.WriteLine($"Operation [{addMessage}] failed. Attempt nr. [{tryIndex}]. Exception: [{ex.Message}]");

            if (tryIndex >= tryCount)
                throw;
        }
    } while (!success);
}

Usage example:

DoWithRetries(() =>
{
    if (rng.Next(0, 3) > 0) // 33%
    {
        throw new Exception("random exception");
    }
    Console.WriteLine("Operation finished successfully");
}, 5, "Random Exception Thrower");

Result:

Operation [Random Exception Thrower] failed. Attempt nr. [1]. Exception: [random exception]
Operation [Random Exception Thrower] failed. Attempt nr. [2]. Exception: [random exception]
Operation finished successfully

Generic serialization/deserialization

        public static void Serialize<T>(String file, T data)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, data);
                File.WriteAllText(file, writer.ToString());
            }
        }

        public static T Deserialize<T>(String file)
        {
            String xml = File.ReadAllText(file);
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            using (StringReader reader = new StringReader(xml))
            {
                return (T)(serializer.Deserialize(reader));
            }
        }