You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
}
}
}
The text was updated successfully, but these errors were encountered:
@cubewise-tryan With your code I get the same buggy behaviour.
You can work around it by changing the order in which you do the transformations, putting the Params transform before the Task<T> transform:
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:
The text was updated successfully, but these errors were encountered: