Following code will cause exception:
string IDs = "";
IDs = IDs.Replace("", "");
Why?
It's right in the documentation for string.Replace(). If you try to replace with the "oldValue" parameter as an empty string, it throws an exception.
Exception Condition
ArgumentException oldValue is the empty string ("").
If you think about it, what are you actually trying to do when you try to find an empty string in another string and replace it with something? Conceptually it doesn't make sense.
Well, what do you expect?
You want to replace nothing with nothing? What exactly do you want to do?
Let's say the old string was "ABC", what would you want it to be after your call to Replace?
In this particular case, the exception thrown is an ArgumentException, and the text of it is that "String cannot be of zero length".
So, the criteria of calling the .Replace method is that what you want to replace is not a string without contents.
Let's check the documentation of String.Replace(String, String):
Under Exceptions it says:
ArgumentNullException, if oldValue is a null reference (Nothing in Visual Basic).
or
ArgumentException, if oldValue is the empty string ("").
So everything is behaving like expected.
The reason for this is that conceptually, every string contains an infinite number of empty strings at the start, at the end, and between characters. (This is why foo.IndexOf("") will always return 0 for any string foo.) Replacing all the infinite amount of empty strings with something else makes no sense as an operation.