title: Passing DateTime variable to controller causing an error
body: <p>I am building a small prediction feature into my application. Running into an issue which I cannot seem to understand. I am calculating some basic results and returning a Dictionary containing the 2 results. Thought this would be a good way to get back both results from one function instead of calling two. I have found some proposed solutions for this error such as converting the DateTime to a string but this did not work for me either. Would appreciate any insight into the cause of the error. Thanks in advance.</p>
  <h2>Error</h2>
  <pre><code>Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
  Unhandled exception rendering component: '&lt;' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
      System.Text.Json.JsonException: '&lt;' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
       ---&gt; System.Text.Json.JsonReaderException: '&lt;' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
         at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader&amp; json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
         at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
         at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
         at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
         at System.Text.Json.Utf8JsonReader.Read()
         at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader&amp; reader, JsonSerializerOptions options, ReadStack&amp; state)
         --- End of inner exception stack trace ---
         at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack&amp; state, JsonReaderException ex)
         at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader&amp; reader, JsonSerializerOptions options, ReadStack&amp; state)
         at System.Text.Json.JsonSerializer.ReadCore[Dictionary`2](JsonConverter jsonConverter, Utf8JsonReader&amp; reader, JsonSerializerOptions options, ReadStack&amp; state)
         at System.Text.Json.JsonSerializer.ReadCore[Dictionary`2](JsonReaderState&amp; readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack&amp; state, JsonConverter converterBase)
         at System.Text.Json.JsonSerializer.&lt;ReadAsync&gt;d__20`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
         at System.Net.Http.Json.HttpContentJsonExtensions.&lt;ReadFromJsonAsyncCore&gt;d__3`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
         at System.Net.Http.Json.HttpClientJsonExtensions.&lt;GetFromJsonAsyncCore&gt;d__9`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
         at WebApp.Client.Pages.Prediction.Predict.InitPrediction() in C:\Users\source\repos\WebApp\WebApp\Client\Pages\Prediction\Predict.razor:line 48
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
  </code></pre>
  <p>This error only started to occur when I started passing a DateTime variable when making the Get request</p>
  <h2>Razor page: problematic</h2>
  <pre><code>[CascadingParameter]
  private DateTime selectedDate { get; set; } = new DateTime();
  private Dictionary&lt;string, int&gt; predictedInfo = new Dictionary&lt;string, int&gt;();
  
   private async Task InitPrediction()
      {
          predictedInfo = await http.GetFromJsonAsync&lt;Dictionary&lt;string, int&gt;&gt;($&quot;Prediction/{selectedDate}&quot;);
          Navigation.NavigateTo(&quot;/prediction&quot;);
      }
  </code></pre>
  <h2>Controller: problematic</h2>
  <pre><code>[HttpGet(&quot;{date}&quot;)]
  public async Task&lt;ActionResult&lt;Dictionary&lt;string, int&gt;&gt;&gt; GetProjects(DateTime date)
  {
  
    int total_projects_per_company = 0;
    int users_per_project_sum = 0;
  
    Dictionary&lt;string, int&gt; d = new Dictionary&lt;string, int&gt;();
  
  // calculation code...
  
  
    d.Add(&quot;users&quot;, users_per_project_sum);
    d.Add(&quot;projects&quot;, total_projects_per_company);
    return d;
  }
  </code></pre>
  <p>The problem does not occur when <strong>I do not pass the DateTime</strong> and I am not sure what the correlation between this is.</p>
  <h2>Razor page: Not causing a problem</h2>
  <pre><code>[CascadingParameter]
  private DateTime selectedDate { get; set; } = new DateTime();
  private Dictionary&lt;string, int&gt; predictedInfo = new Dictionary&lt;string, int&gt;();
  
  private async Task InitPrediction()
  {
    predictedInfo = await http.GetFromJsonAsync&lt;Dictionary&lt;string, int&gt;&gt;(&quot;Prediction&quot;);
    Navigation.NavigateTo(&quot;/prediction&quot;);
  }
  </code></pre>
  <h2>Controller: Not causing a problem</h2>
  <pre><code>[HttpGet]
  public async Task&lt;ActionResult&lt;Dictionary&lt;string, int&gt;&gt;&gt; GetProjects()
  {
    int total_projects_per_company = 0;
    int users_per_project_sum = 0;
  
    Dictionary&lt;string, int&gt; d = new Dictionary&lt;string, int&gt;();
   // calculation code...
    d.Add(&quot;users&quot;, users_per_project_sum);
    d.Add(&quot;projects&quot;, total_projects_per_company);
    return d;
  }
  </code></pre>