0

I am using NUnit GUI Runner to execute my Test suite developed in Selenium Webdriver C#.

Everytime I am getting error Length cannot be less than zero.

If I change the relative path with absolute path then it is working fine. So is there any limitation with Relative Path. Please advise.

NUNIT Version :2.6.4.14350 Framework Version :Net 3.5 Visual Studio 2013

My Code is like this:

String relativePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); relativePath = relativePath.Substring(0, relativePath.IndexOf("TestResults"));

So if I change the value for relativePath as "C:\demo\" then it is working fine.

1 Answers1

0

Most likely, this happens due to the fact that relativePath does not contain "TestResults" substring and therefore IndexOf() call returns -1. Substring call cannot accept negative value as its second argument (length of the substring).

  • Thanks for your reply but TestResults folder is there,so there is no issue with Substring. Infact when I add the code in Watch section it was returning value as 68. – AJIT KUMAR Apr 24 '15 at 17:35
  • Issue resolved.Updated my code and included Math.Max. relativePath = relativePath.Substring(0, Math.Max(0,relativePath.IndexOf("TestResults"))); – AJIT KUMAR Apr 24 '15 at 17:39