Home > Articles > Details

ArgumentException: String cannot be of zero length. (Parameter 'oldValue')

Question: I have this error, how do I solve it? ArgumentException: String cannot be of zero length. (Parameter 'oldValue')


Please Login to see the rest of the answer
Answer: You are using the .ToString() without passing in the argument. There is a chance that you are trying to convert a #DateTime.Now to a string, remember the #DateTime is a a Struct that is more like a Class, in short it is an object containing Date related #variables, you cannot just turn that object into a plain all String.

In order to resolve this issue, add a paremeter inside the .ToString() like below:

string path = Url.Content(Path.Combine("wwwroot", "MyFolderOne", "MyFolder", $"MyReportName-{DateTime.Now.ToString("yyyyMMdd").Replace("/", "-")}.pdf"));

If this answer helped you solve your problem, leave us a comment below.

If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Jack said:

For me it was because I used Replace empty strings, once I removed that it was okay.

Posted On: March 30, 2022 17:14:29 PM

© 2022 - ErnesTech - Privacy