title: Constant expression required error setting optional parameter in function
body: <p>Why am I getting a </p>
  
  <blockquote>
    <p>Constant Expression Required</p>
  </blockquote>
  
  <p>error with the following VB.net code?</p>
  
  <pre><code>Public Shared Async Function DownloadAndCountBytesAsync(url As String, Optional token As CancellationToken = New CancellationToken) As Task(Of Integer)
  </code></pre>
  
  <p>Swapping <code>New CancelationToken</code> with <code>Nothing</code> and adding </p>
  
  <pre><code>If token = Nothing Then token = New CancellationToken
  </code></pre>
  
  <p>to the function works but I don't understand why the first option doesn't work...</p>
  
  <p>The same thing seems to work fine in C#</p>
  
  <pre><code>public static async Task&lt;int&gt; DownloadAndCountBytesAsync(string url, CancellationToken token = new CancellationToken())
  </code></pre>