Excel-DNA / Excel-DNA/ExcelDna
Crash Excel when using cell of a udf as a calculation
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 292
- Avg merge
- 20d 12h
- Merged PRs (30d)
- 1
Description
I was having no issues until quite recently with UDF using `ExcelAsyncHandle` and now whenever I'm in manual calculation mode and use the result cell of a function using it, then press Shift+F9, Excel crash with a 255 error code, no other info
the below code can reproduce it, I've taken it from the samples
```
using System;
using System.Threading.Tasks;
using ExcelDna.Integration;
public class Test : IExcelAddIn
{
public void AutoOpen()
{
ExcelIntegration.RegisterUnhandledExceptionHandler(ex => "!!!Error " + ex);
}
public void AutoClose()
{
}
// .NET 4.5 only (or using the .NET 4.0 async/await library)
[ExcelFunction(Description = "This function wraps a call to the 'DelayedEcho' task")]
public static async void dnaEchoNewAsync(object valueToEcho, int msToSleep, ExcelAsyncHandle asyncHandle)
{
try
{
object result = await DelayedEcho(valueToEcho, msToSleep);
asyncHandle.SetResult(result);
}
catch (Exception ex)
{
asyncHandle.SetException(ex);
}
}
static async Task DelayedEcho(object valueToEcho, int msToDelay)
{
if (valueToEcho.Equals("Boom!")) throw new Exception("Boom! Boom! Boom!");
await Task.Delay(msToDelay);
return valueToEcho;
}
private static async Task Delayed(int msToDelay)
{
await Task.Delay(msToDelay);
var result = new object[1, 2];
result[0, 0] = 100;
result[0, 1] = 200;
return result;
}
[ExcelFunction()]
public static async void AsyncArray(int msToSleep, ExcelAsyncHandle asyncHandle)
{
try
{
object result = await Delayed(msToSleep);
asyncHandle.SetResult(result);
}
catch (Exception ex)
{
asyncHandle.SetException(ex);
}
}
}
```
1. I enter the udf in 2 cells (`=AsyncArray(5000)`) press ctrl + shift + enter and the result appears after 5s
2. Now in another cell I add 1 to the 100 returned, press enter, 101 appears
3. Then I press shift+f9 and excel crash, sometines it doesnt crash right away so repeat from 1 and it's crashing.
Happy to give more info if necessary !
Contributor guide
Assessment
This issue has not been assessed yet.