IIS web service and aggregate queries -- Lua issues

I’m having a bear of a time trying to get the Aerospike client library to work with my .net web project. I have a WCF web service that queries my Aerospike cluster and tries to run an aggregate query. Everything is fine if I do a simple query, but an aggregate that requires loading the Lua51.dll blows up. I’ve tried updating the client library to use NLua, but still no dice. Is there any way I can execute aggregate queries via a WCF service? Everything runs fine btw when I execute my code in a console app. I’m guessing IIS doesn’t like the Lua51/Lua52 dlls for some reason. I’ve also tried this with the included example code, again console app is fine but the minute I try it in WCF land there are issues.

Adding, here’s the specifics (this is after I modified the client to use NLua; I get the same thing with the current Lua lib):

Unable to load DLL ‘lua52’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

at KeraLua.NativeMethods.LuaLNewState() at NLua.Lua…ctor() at Aerospike.Client.LuaInstance…ctor() in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Lua\LuaInstance.cs:line 32 at Aerospike.Client.LuaCache.GetInstance() in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Lua\LuaCache.cs:line 34 at Aerospike.Client.QueryAggregateExecutor.RunThreads() in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Query\QueryAggregateExecutor.cs:line 65 at Aerospike.Client.QueryAggregateExecutor.Run(Object obj) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Query\QueryAggregateExecutor.cs:line 55

EDIT: Adding, I’ve tried all the various config options to ensure that there were no issues with 32 vs 64 bit and etc.

Found this little tidbit that makes porting to Lua52 fun:

{“[string "aerospike"]:212: attempt to call global ‘setfenv’ (a nil value)”}

at NLua.Lua.ThrowExceptionFromError(Int32 oldTop) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\NLua-master\Core\NLua\Lua.cs:line 365 at NLua.Lua.CallFunction(Object function, Object args, Type returnTypes) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\NLua-master\Core\NLua\Lua.cs:line 787 at NLua.Lua.CallFunction(Object function, Object args) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\NLua-master\Core\NLua\Lua.cs:line 757 at NLua.LuaFunction.Call(Object args) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\NLua-master\Core\NLua\LuaFunction.cs:line 75 at Aerospike.Client.LuaInstance.Call(String functionName, Object args) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Lua\LuaInstance.cs:line 93 at Aerospike.Client.QueryAggregateExecutor.RunThreads() in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Query\QueryAggregateExecutor.cs:line 85 at Aerospike.Client.QueryAggregateExecutor.Run(Object obj) in c:\AerospikeClient\aerospike-client-csharp-3.0.12\AerospikeClient\Query\QueryAggregateExecutor.cs:line 55

I guess Lua supports sandboxing, but in 5.2 you have to specify that as part of the constructor instead of changing it on-the-fly (if I understand the discussion correctly) – Recreating setfenv() in Lua 5.2 - Stack Overflow

It looks like, so far anyways, a possible solution is to port to NLua_Safe (it doesn’t P/Invoke the Lua51.dll). It took about five minutes to update the client lib so it could use NLua, but if (after I’ve tested everything) anyone wants access to this code I could make it available on Github and/or update the main Aerospike C# client library. This method is apparently slower (by about 10x over using P/Invoke), but so far I haven’t had any compatibility issues and it should only affect the execution speed of the final step that executes in client code.

EDIT: Success! I can run the query_average code in my WCF and it returns the expected result. NLua_Safe so far is working.