title: Failed to convert parameter value from a Int64 to a Byte[]
body: <p>I am getting the error:</p>
  
  <blockquote>
    <p>Failed to convert parameter value from
    a Int64 to a Byte[].</p>
  </blockquote>
  
  <p>Here is what I am doing...</p>
  
  <p>I have a table in my database with the column:</p>
  
  <pre><code>sessionid | binary(32) | null
  </code></pre>
  
  <p>When I assign to it, I do this: </p>
  
  <pre><code>user.LastActivityDate = DateTime.Now;
  user.SessionId = user.LastActivityDate.ToBinary();
  </code></pre>
  
  <p>SessionId is an inherited property from an interface:</p>
  
  <pre><code>long? SessionId { get; set; }
  </code></pre>
  
  <p>And here it is being accessed in my User class: </p>
  
  <pre><code>[SettingsAllowAnonymous(false), CustomProviderData("SessionId;string")]
  public long? SessionId { get { return base["SessionId"] as long?; } set { base["SessionId"] = value; } }
  </code></pre>
  
  <p>In my custom profile provider, the following command assigns the value: </p>
  
  <pre><code>sqlCommand.Parameters.Add("sessionid", SqlDbType.Binary, 32).Value = settingsPropertyValue.PropertyValue;
  </code></pre>
  
  <p>When the "sqlCommand.ExecuteNonQuery()" command executes an update stored 
  procedure is executed with the parameter:</p>
  
  <pre><code>@sessionid binary(32)
  </code></pre>
  
  <p>And the result is the error: </p>
  
  <blockquote>
    <p>"Failed to convert parameter value
    from a Int64 to a Byte[]."</p>
  </blockquote>
  
  <p>I have tried:</p>
  
  <ol>
  <li>... = Convert.ToByte(settingsPropertyValue.PropertyValue);</li>
  <li>... = Convert.ToInt64(settingsPropertyValue.PropertyValue);</li>
  </ol>
  
  <p>Any ideas? Thanks.</p>