title: Net Core 3.1 Return a Task with a result that includes details of the exception?
body: <p>I am using ADO.Net to fill a datatable, the datatable fill method I have put into a separate repository. I inject the repository/interface into a test page model. The page model method "OnPostUpdateAlarmDataTableAsync"needs to call the interface and request the datatable to to be filled. I want to return the result from the task that fills this table, so if the task fails for what ever reasons, I can then inform the user on the UI, I also want to log the details of the error from the page model since this is the calling thread.</p>
  
  <p>Current compile error says "cannot assign void to an implicitly-typed variable" But what ever combination in code changes I try, something never compiles properly. Being able to return the task from an async operation with the relevant info that contains details about the exception is what I want to achieve.</p>
  
  <p>Interface:</p>
  
  <pre><code>public interface IAdoNetRepository
  {
      Task FillAlarmsDataTable();
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>public class AdoNetRepository : IAdoNetRepository
  {
      public readonly IConfiguration _config;
  
      public AdoNetRepository(IConfiguration config)
      {
          _config = config;
      }
  
      // Used for method below GetUserGroupsData()
      public static SqlDataAdapter dataAdapter = new SqlDataAdapter();
      public static DataTable alarmDataTable;
  
  
      public async Task FillAlarmsDataTable()
      {
          string connectionString = _config.GetConnectionString("Data:DefaultConnection:ConnectionString");
  
          try
          {
              SqlConnection connection = new SqlConnection(connectionString);
              string cmdText1 = "SELECT * FROM [dbo].[Alarms] ORDER BY Name";
  
              // Create a new data adapter based on the specified query.
              dataAdapter = new SqlDataAdapter(cmdText1, connection);
  
              // Populate a new data table and bind it to the BindingSource.
              alarmDataTable = new DataTable
              {
                  Locale = CultureInfo.InvariantCulture
              };
              await Task.Run(() =&gt; dataAdapter.Fill(alarmDataTable));
              //dataAdapter.Fill(alarmDataTable);
  
              return; // Return what ?
          }
          catch (Exception ex)
          {
              // Return the task with details of the exception
              return; // Return what?
          }
      }
  }
  </code></pre>
  
  <p>PageModel:</p>
  
  <pre><code>public class TestModel : PageModel
  {
  
      private readonly IAdoNetRepository _adoNetRepository;
  
      public TestModel(IAdoNetRepository adoNetRepository)
      {
          _adoNetRepository = adoNetRepository;
      }
  
      public async Task&lt;IActionResult&gt; OnPostUpdateAlarmDataTableAsync()
      {
          // This gets squiggly line compile error            
          var result = await _adoNetRepository.FillAlarmsDataTable();
  
          if (!result.Succeeded)
          {
              // log the exception returned from the task that failed!
          }
  
          return new JsonResult(result);
      }
  }
  </code></pre>