This error usually occurs when you use symbols that have defined meanings in the format string. The best way to debug these is selectively remove characters until it works. The last character you removed was the problem one.
In this case, looking at the custom TimeSpan format strings, the square brackets are the problem. Escape them with "\", for example:
var ts = new TimeSpan(0, 3, 25, 0);
var myString = ts.ToString("\\[d'.'\\]hh':'mm");
[Edit: Added]
There is no way mentioned on the customer custom TimeSpan format strings page to omit text if values are 0. In this case, consider an if
statement or the ?:
operator.