This may be annoying if you don't check the old value or don't trap this exception.
A radical workaround would be to introduce a little overload with your own static method or by extending the System.String class with a "safe" method like :
/// <summary>
/// Extensions for System.String class
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Safely replace all occurrences of specified System.String instance, with another System.String instance
/// </summary>
public static string SafeReplace(this string extendedString, string oldValue, string newValue)
{
if (string.IsNullOrEmpty(oldValue))
{
return extendedString;
}
return extendedString.Replace(oldValue, newValue);
}
}
