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')

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 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 parameter inside the .ToString() like below:

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

 


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

© 2023 - ErnesTech LLC- Privacy