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"));

 





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

For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]