Excel-DNA / Excel-DNA/Registration

Async Function with params

Open
#25 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
37
Forks
19
PR merge metrics
No merged PRs in 30d

Description

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 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;
}

}

}

}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.