Registration icon indicating copy to clipboard operation
Registration copied to clipboard

Async Function with params

Open cubewise-tryan opened this issue 4 years ago • 2 comments

Hi,

I am trying to do a POC creating a function that allows an asynchronous call with unlimited number of arguments. When adding async Task as the return type the fixed arguments in the function are always empty and only the params are populated. If I return object the fixed arguments are available.

Not sure if I am doing something incorrectly or there is a bug.

Sample code below:

using System;
using System.Net;
using System.Diagnostics;

using ExcelDna.Integration;
using ExcelDna.Registration;
using ExcelDna.Logging;

namespace test
{
   public class AddIn : IExcelAddIn
   {

      public void AutoOpen()
      {
         ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

         Trace.Listeners.Add(new LogDisplayTraceListener());

         ExcelRegistration.GetExcelFunctions()
                          .ProcessAsyncRegistrations(nativeAsyncIfAvailable: false)
                          .ProcessParamsRegistrations()
                          .RegisterFunctions();
      }

      public void AutoClose()
      {

      }

   }

}
using System;
using System.Threading.Tasks;
using System.Diagnostics;
using ExcelDna.Integration;

namespace test
{
   public static class MyFunctions
   {
      [ExcelFunction(Description = "Returns a value")]
      public static async Task<object> NotWorking([ExcelArgument(Name = "Arg1", Description = "Arg 1")] string arg1, 
         [ExcelArgument(Name = "Argument", Description = "Arg 2, Arg 3, etc")]params string[] args)
      {
         try {
            var result = arg1 + ", " + String.Join(", ", args);
            Trace.TraceInformation(result);
            Trace.Flush();
            return result;
         } catch (Exception ex){
            Trace.TraceError(ex.Message);
            Trace.Flush();
            return ex.Message;
         }
         
      }

      [ExcelFunction(Description = "Returns a value")]
      public static object Working([ExcelArgument(Name = "Arg1", Description = "Arg 1")] string arg1, 
         [ExcelArgument(Name = "Argument", Description = "Arg 2, Arg 3, etc")]params string[] args)
      {
         try {
            var result = arg1 + ", " + String.Join(", ", args);
            Trace.TraceInformation(result);
            Trace.Flush();
            return result;
         } catch (Exception ex){
            Trace.TraceError(ex.Message);
            Trace.Flush();
            return ex.Message;
         }
         
      }


   }

}

cubewise-tryan avatar Aug 28 '19 00:08 cubewise-tryan