Have you debugged the code? Are you sure the second line returns a value other than -1? If there is no backslash in the string, LastIndexOf will return -1, which is not a valid index that Substring can use, and thus the error "index out of bounds" will be Substring .
A safer method is to extract the file name using the methods defined in the Path class. But keep in mind that the project name does not necessarily match the assembly name.
Frederik gheysels
source share