title: Exception: Specified cast is not valid
body: <pre><code>public class UserLoginInfo
  {
      public UserRole Role;
      public string Username;
  
      public static UserLoginInfo FetchUser(string username, string password)
      {
          using (var connection = Utils.Database.GetConnection())
          using (var command = new SqlCommand("SELECT [Username], [Password], [Role] FROM [Users] WHERE [Username] = @username", connection))
          {
              command.Parameters.AddWithValue("@username", username);
              using (var reader = command.ExecuteReader())
              {
                  if (reader == null || !reader.Read() || !Utils.Hash.CheckPassword(username, password, (byte[])reader["Password"]))
                      throw new Exception("Wrong username or password.");
  
                  return new UserLoginInfo { Username = (string)reader["Username"], Role = (UserRole)reader["Role"] };
              }
          }
      }
  }
  </code></pre>
  
  <p>When I put a breakpoint and debug the error comes from this line </p>
  
  <pre><code>return 
      new UserLoginInfo 
      { 
          Username = (string)reader["Username"], 
          Role = (UserRole)reader["Role"] 
      };
  </code></pre>
  
  <p>I don't understand why I get this error. Please help me!</p>
  
  <p>EDIT: How can I convert (string)reader["Role"] to UserRole??</p>
  
  <pre><code>public enum UserRole
  {
      Admin,
      Maintance,
      User
  }
  </code></pre>