title: Azure Function v2 and system.text.json
body: <p>I am trying to implement a function that uses .net core 3 (preview 9) as a target framework and uses the new System.text.json namespace. Here is my code:</p>
  
  <pre><code>using System;
  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Host;
  using Microsoft.Extensions.Logging;
  using System.Text.Json;
  
  namespace Backtester
  {
      public class Test
      {
          public string Author { get; set; }
          public string Currency { get; set; }
      }
  
      public static class Function
      {
          [FunctionName("Function")]
          public static void Run([ServiceBusTrigger("%QueueName%", Connection = "AzureWebJobsServiceBus")]string myQueueItem, ILogger log)
          {
              try
              {
                  var request = JsonSerializer.Deserialize&lt;Test&gt;(myQueueItem);
                  log.LogInformation($"Currency: {request.Currency} - {request.Author}");
              }
              catch (Exception ex)
              {
                  throw;
              }
          }
      }
  }
  </code></pre>
  
  <p>When I run the code and submit a message onto the service bus queue, the function is triggered but fails with the following error:</p>
  
  <pre><code>[13/09/2019 13:01:25] System.Private.CoreLib: Exception while executing function: Function. Backtester: Could not load file or assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058). Cannot load a reference assembly for execution.
  [13/09/2019 13:01:25] MessageReceiver error (Action=UserCallback, ClientId=MessageReceiver1********************, EntityPath=**********, Endpoint=**********************************)
  [13/09/2019 13:01:25] System.Private.CoreLib: Exception while executing function: Function. Backtester: Could not load file or assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058). Cannot load a reference assembly for execution.
  </code></pre>
  
  <p>I'm coming to the conclusion that I will have to downgrade my project to .net core 2.2, which will cause a fair amount of work as I have a web project up and running using the new codebase.</p>