# Error loading udf (C# client)

**URL:** <https://discuss.aerospike.com/t/error-loading-udf-c-client/1645>\
**Category:** User Defined Functions (UDF)\
**Created:** [August 17, 2015, 7:59am UTC](https://discuss.aerospike.com/t/error-loading-udf-c-client/1645 "2015-08-17T07:59:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erwin](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@erwin](https://discuss.aerospike.com/u/erwin)\
**Post date:** [August 17, 2015, 7:59am UTC](https://discuss.aerospike.com/t/error-loading-udf-c-client/1645/1 "2015-08-17T07:59:20Z")

</div>

Hi,

I’m trying to scan over a secondary index and want to handle all records of which the secondary index is null or empty. Therefore I created the following lua script:

```
local function notNullOrEmpty(val)
    return val ~= nil and val ~= ''
end

function cid_filter(stream)
return stream : notNullOrEmpty(record.cid)
end

```

I registered the user defined function using the following command:

```
string udf = "scan_index.lua";
RegisterTask registerTask = client.Register(null, udf, udf, Language.LUA);
registerTask.Wait();

```

The registration seems to be ok and when I check the server the scan\_index.lua file is in directory udf/lua

```
/opt/aerospike/usr/udf/lua$ dir
scan_index.lua

```

I execute the QueryAggregate method like this

```
Statement statement = new Statement();
statement.SetNamespace(ns);
statement.SetSetName(set);
statement.SetAggregateFunction(udf, filter);

using (ResultSet rs = client.QueryAggregate(null, statement)) { /*some logic here*/ }

```

And the following error occurs

```
2015-08-17 07:46:19 1 ERROR Exception occurred while testing Aerospike. [Exception:
    Aerospike.Client.AerospikeException: Query Failed: Error Code 4: Failed to find 'scan_index.lua' in 'udf\?.lua' --->
    Aerospike.Client.AerospikeException: Error Code 4: Failed to find 'scan_index.lua' in ' udf\?.lua'
at Aerospike.Client.LuaInstance.FindFile(String packageName)
at Aerospike.Client.LuaInstance.LoadPackageFromFile(String packageName)
at Aerospike.Client.LuaInstance.LoadPackage(Statement statement)
at Aerospike.Client.QueryAggregateExecutor.Run(Object obj)
--- End of inner exception stack trace ---
at Aerospike.Client.QueryExecutor.CheckForException()
at Aerospike.Client.ResultSet.Next()
at BTTester.Program.ScanIndex(AerospikeClient client, String ns, String set, ProfileIndexTypes index)
at BTTester.Program.TestAerospike()]

```

Does anyone have an idea what the problem can be? I already tried to move the scan\_index.lua on my client application into a subfolder /udf and /udf/lua but the problem still occurs.

Thanks in advance for any tips that can resolve my problem,

Erwin

---

<div class="post-metadata">

**Author:** ![erwin](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@erwin](https://discuss.aerospike.com/u/erwin)\
**Post date:** [August 19, 2015, 6:41am UTC](https://discuss.aerospike.com/t/error-loading-udf-c-client/1645/2 "2015-08-19T06:41:35Z")

</div>

Hi,

After some experimenting and reading I found the solution for my problem. There where 2 issues:

- My Lua scripts were not in the folder udf on my client machine. To fix this I had to either create an udf subfolder or set the Lua path using: _LuaConfig.PackagePath = @“.?.lua”;_
- When calling the SetAggregateFunction method, I provided _scan\_index.lua_ as packageName but this had to be _scan\_index_ (without the extension)

Regards,

Erwin
