title: Specified cast error
body: <p>I am using VS2012 with <code>ASP.NET 4.5</code> and <code>MySQL</code> as my database provider.
  I am getting a specified cast error now on code that was working fine at one point.
  It is from my Register.aspx page for registration verification and the code is adapted from an asp.net website tutorial.</p>
  
  <p>Here is the code, the error is on the <code>Dim newUser as Guid</code> line</p>
  
  <pre><code>Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
      FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)
  
  
      Dim newUser As MembershipUser = Membership.GetUser(RegisterUser.UserName)
      Dim newUserID As Guid = DirectCast(newUser.ProviderUserKey, Guid)
      Dim urlBase As String = Request.Url.GetLeftPart(UriPartial.Authority) &amp; Request.ApplicationPath
      Dim verifyUrl As String = "VerifyNewUser.aspx?ID=" &amp; newUserID.ToString()
      Dim fullPath As String = urlBase &amp; verifyUrl
      Dim appPath As String = Request.PhysicalApplicationPath
  
      Dim sr As New StreamReader(appPath &amp; "EmailTemplates/VerifyUserAccount.txt")
      Dim mailMessage As New MailMessage()
      mailMessage.IsBodyHtml = True
      mailMessage.From = New MailAddress("myacct@gmail.com")
      mailMessage.To.Add(New MailAddress(RegisterUser.Email))
      mailMessage.CC.Add(New MailAddress("myacct@gmail.com"))
      mailMessage.Subject = "New User Registration"
      mailMessage.Body = sr.ReadToEnd
      sr.Close()
  
      mailMessage.Body = mailMessage.Body.Replace("&lt;%UserName%&gt;", RegisterUser.UserName)
      mailMessage.Body = mailMessage.Body.Replace("&lt;%VerificationUrl%&gt;", fullPath)
  
      //Set up the smtp for gmail to send the email
      Dim mailClient As New SmtpClient()
      With mailClient
          .Port = 587 'try 465 if this doesn't work
          .EnableSsl = True
          .DeliveryMethod = SmtpDeliveryMethod.Network
          .UseDefaultCredentials = False
          .Credentials = New NetworkCredential(mailMessage.From.ToString(), "password")
          .Host = "smtp.gmail.com"
      End With
      mailClient.Send(mailMessage)
  
      Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
      If String.IsNullOrEmpty(continueUrl) Then
          continueUrl = "~/"
      End If
  
      Response.Redirect(continueUrl)
  End Sub
  </code></pre>