Calling Optix code from C# and managing Optix dependencies

For the project I am working on we have written a very simple Optix Prime program that calculates the intersection of a triangulated model and a bunch a lines for a non-raytracing application. The program works great and we get awesome performance.

Now we need to be able to call the c++ Optix Prime function from C#. Since the code is pretty simple I am trying to do this using DllImport, however no matter what I try I cannot get the dll for the Optix Prime program to import in C#, I always get the error: “Unable to load DLL ‘primeSimplePP.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E).” I have made sure that the dll is in the output directory of the C# project and I used dependency walker to see what else the dll is dependant on. Dependency walker shows that my dll (which is really just a modification of the primeSimplePP example) depends on SUTIL.DLL and OPTIX-PRIME.1.DLL as well as well as MSVCP120.DLL, MSVCR120.DLL, and KERNEL32.DLL. Unless my understanding is wrong, the last three shouldn’t be a problem as they reside in the system32 directory (although I tried putting them in the ouptut directory as well just in case, but no dice). Therefore, I have also put SUITL.DLL and OPTIX_PRIME.1.DLL in the output directory, but I still get the error.

Dependency walker also says that there are several dlls that it cannot find:

API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-SHUTDOWN-L1-1-1.DLL
EXT-MS-WIN-NTUSER-UICONTEXT-EXT-L1-1-0.DLL
IESHIMS.DLL

In the digging that I have done, it looks like these DLLs are ones that were changed with Windows 8.1, and some of them have been removed completely, so i can’t just try to references to them to see if it fixes it. That being said, many people have reported that this is often a false negative and that many programs should work anyway, which lines up with what I see when I run the program from the .exe (or straight from visual studio), it runs without a problem. However, no matter what I do I always get the error telling me that there are DLLs missing.

Are these dependencies the problem? Are there other dependencies that I am missing? Is there a better way to call my optix program from c# that people have had success with in the past?

First, OptiX as well as OptiX Prime are using C APIs as foundation, not C++.
Anything C++ you see in the OptiX or OptiX Prime examples are wrappers around those C APIs.
You’ll find their implementations inside the headers optixpp_namespace.h resp. optix_primepp.h.

There exists no primeSimplePP.dll because primeSimplePP is one of the SDK’s example applications built as executable. It shows a comparison between the fundamental OptiX Prime C API used in primeSimple and the C++ wrappers used in primeSimplePP.

The OptiX Prime C API is implemented inside the optix_prime.1.dll. Similarly for OptiX in optix.1.dll.
Your OptiX Prime based application needs to link against the optix_prime.1.lib export library or load the C API entry points dynamically to use all of them.

Means you would normally implement an interface in your target language, here C#, which calls the fundamental C API of an SDK underneath.
Once you have that interface you would be able to port any of the OptiX Prime examples to your native target language.
I have no experience with C# so you need to figure out these parts yourself.

There is no requirement to link against sutil in own applications. That is a collection of helper functions for the OptiX SDK examples. It’s just implementing what the OptiX SDK examples needed at that time, and the next major OptiX release version does it differently, so this is also not meant to be stable code. You should rather implement the necessary functionality for your application in your own programming language.

My recommendation how to start learning OptiX can be found in this post, similarly for OptiX Prime.
https://devtalk.nvidia.com/default/topic/915251/?comment=4801716