Input string was not in a correct format.
It's pretty clear. You are trying to convert some data into a datatype that is incorrect.
Based on the line you mention, this means that username is not of type
. Further, AFAIK,
is of type
. Thus, when you try to convert it into
, you get an error. It's a string, not an integer.
Refer: MSDN: Environment.UserName Property