diff --git a/Source/ExcelDna.Integration/Registration/ParamsRegistration.cs b/Source/ExcelDna.Integration/Registration/ParamsRegistration.cs
index 5e0bf48c..450e58f7 100644
--- a/Source/ExcelDna.Integration/Registration/ParamsRegistration.cs
+++ b/Source/ExcelDna.Integration/Registration/ParamsRegistration.cs
@@ -144,8 +144,8 @@ static LambdaExpression WrapMethodParams(LambdaExpression functionLambda)
*
*/
- int maxArguments = 125; // Constrained by 255 char registration string, take off 3 type chars, use up to 2 chars per param (before we start doing object...) (& also return)
- // CONSIDER: Might improve this if we generate the delegate based on the max length...
+ int maxArguments = NativeAOT.IsActive ? 16 : 125; // Constrained by 255 char registration string, take off 3 type chars, use up to 2 chars per param (before we start doing object...) (& also return)
+ // CONSIDER: Might improve this if we generate the delegate based on the max length...
var normalParams = functionLambda.Parameters.Take(functionLambda.Parameters.Count() - 1).ToList();
var normalParamCount = normalParams.Count;
@@ -210,13 +210,19 @@ static LambdaExpression WrapMethodParams(LambdaExpression functionLambda)
if (maxArguments == 125)
{
delegateType = typeof(CustomFunc125<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>)
- .MakeGenericType(allParamTypes.ToArray());
+ .MakeGenericType(allParamTypes.ToArray());
}
- else // if (maxArguments == 29)
+ else if (maxArguments == 29)
{
delegateType = typeof(CustomFunc29<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>)
.MakeGenericType(allParamTypes.ToArray());
}
+ else // if (maxArguments == 16)
+ {
+ delegateType = typeof(Func<,,,,,,,,,,,,,,,,>)
+ .MakeGenericType(allParamTypes.ToArray());
+ }
+
return Expression.Lambda(delegateType, blockExpr, allParamExprs);
}
}
diff --git a/Source/ExcelDna.SourceGenerator.NativeAOT/Generator.cs b/Source/ExcelDna.SourceGenerator.NativeAOT/Generator.cs
index ad6e109a..30f6b816 100644
--- a/Source/ExcelDna.SourceGenerator.NativeAOT/Generator.cs
+++ b/Source/ExcelDna.SourceGenerator.NativeAOT/Generator.cs
@@ -30,6 +30,9 @@ public void Execute(GeneratorExecutionContext context)
string source = """
//
+using System;
+using System.Collections.Generic;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -44,7 +47,7 @@ public static short Initialize(void* xlAddInExportInfoAddress, void* hModuleXll,
[ADDINS]
- [FUNCTIONS]
+[FUNCTIONS]
return ExcelDna.ManagedHost.AddInInitialize.InitializeNativeAOT(xlAddInExportInfoAddress, hModuleXll, pPathXLL, disableAssemblyContextUnload, pTempDirPath);
}
@@ -68,16 +71,26 @@ public static short Initialize(void* xlAddInExportInfoAddress, void* hModuleXll,
source = source.Replace("[ADDINS]", addIns);
}
{
- string functions = "List functionTypes = new List();\r\n";
+ string functions = "List typeRefs = new List();\r\n";
+ string methods = "List methodRefs = new List();\r\n";
foreach (var i in receiver.Functions)
{
functions += $"ExcelDna.Integration.NativeAOT.MethodsForRegistration.Add(typeof({Util.GetFullTypeName(i.ContainingType)}).GetMethod(\"{i.Name}\")!);\r\n";
- functions += $"functionTypes.Add(typeof({Util.MethodType(i)}));\r\n";
+ functions += $"typeRefs.Add(typeof({Util.MethodType(i)}));\r\n";
foreach (var p in i.Parameters)
- functions += $"functionTypes.Add(typeof(Func