Handling user having 3rd party DLL

Hi,
I have an addon which uses newton.json. The issue I am hitting is that a lot of users will have another addon which has this DLL already bundled into their custom addon. The issue I hit then is when they attempt to import one it fails due to a clash due to that third party DLL.

What is the best way to resolve this issue and handle it? I can’t export my addon without including that DLL.
Thanks

Ive had the same issue when trying to create a machine learning model with microsoft ML for ninjatrader. I havent messed with it yet but i think the issue stems from 2 libraries having identically named functions. If the dlls are identically named rename it. If its the functions maybe rename the functions.

In my opinion, the best approach is to merge your two DLLs into a single DLL and include the merged DLL in your export zip file. This way any time you install a new version of your package, it will attempt to only overwrite your DLL (combined DLL) and won’t touch the other vendor’s NewtonSoft DLL, so there won’t be a conflict.

There is a free utility called ILMerge that you can use, but I don’t think it gives you the code obfuscation/security capabilities as Agile.net. I haven’t used this approach and can’t provide details. I’m sure you can search for it online.

If you have SecureTeam Agile.net, it has a merge capability and you can utilize the code obfuscation and security features that come with Agile.net. I recently had to do this and I had multiple 3rd party DLLs that I needed to merge into a single DLL. Agile.net does this pretty well and generates a combined DLL that works when imported. It took some trial & error to get things right.

If you have Agile.net and want more detailed instructions, let me know and I’ll elaborate. You’ll need to pick the appropriate options in Agile.net to take advantage of security features. And not all options provide a DLL that imports correctly on a third system. So you need to pick the correct options.

Yes this sounds like a good approach, as you say the issue is simply the name of the DLL conflicting. Quite annoying really we don’t have a good JSON library built in for NT.

I do have Agile.Net, (at least the one for NT), so I would appreciate if you could provide info on how to merge this functionality in. I assume the goal is to build a .dll externally of NT and then feed that into NT when i build the final .zip?

Here’s the process to combine an NT assembly with 1 or more third party assemblies using Agile.net.

First you need to know which options are used by AgileDotNet when it does its magic behind the scenes. To do that, launch AgileDotNet GUI from the Windows Start menu under Secure Team.

The default settings for the inline process reside in this file: C:\Program Files\NinjaTrader 8\bin\Custom\Backup\AgileDotNet.cls

From GUI > Open Project and point it to the above file. Make sure not to make any changes to this file and leave it as is.

Click through all the tabs in the GUI and note which options are set. You’ll see that the only option used is the “Code Encryption”. None of the other security features are enabled.

I don’t want to open another can of worms here and this is probably a topic for a whole another conversation, but it’s worth noting that this limited security could be somewhat concerning. The String Obfuscation option would have been really good to have. Especially if you have embedded string passwords in your code. If String Obfuscation isn’t enabled, these strings can be extracted from the DLL which is a major security concern with passwords/URLs/etc. But enabling any other options aside from the Code Encryption option, seems to generate an assembly that doesn’t import cleanly on the 3rd party system and causes all sorts of other issues. I’ll let you experiment with the various options on your own, but most likely you’ll reach the same conclusion. Just keep in mind that, if you have embedded password or other sensitive information in your code, be aware that they can be extracted from the DLL by potential hackers so try to avoid doing this or find an alternate solution.

Going back to the original process …

I assume that by now you already have your 3rd party assemblies incorporated into NT and added them as References in NinjaScript editor, so I won’t get into that.

Next step: Tools > Export > NinjaScript Add-on
Check the checkbox for Export as compiled assembly
Uncheck the box for Protect compiled assembly (protection comes later and is done manually)
If you leave protection on in this stage, the Build process later will have issues so make sure this is unchecked.
Include all your scripts and add the 3rd party assemblies as References.
Export

You’ll get a warning that says something to the effect that the other system will need to have the 3rd party assembly installed for your assembly to work. This is fine, just accept this and proceed.

The zip file that is created will contain the NT assembly and a file called Reference (or something similar). This Reference file can be removed and isn’t needed.

Copy the DLL file from the zip into a temporary folder on your system.
Copy your 3rd party assembly DLL file/files into the same folder.
Launch AgileDotNet GUI

Input Tab: Add all your assemblies, your main one should be the first entry.
Code Encryption tab: Check all assemblies
Make sure all other options on other tabs are disabled (same as the default NT one)
Merging tab: Select your main assembly as Primary Assembly and check the checkboxes for all the ones in the panel below.
Press the Build button.

You can save all of your settings/etc as a project file by going to Save Project. You can reopen this file at a later time if you want to update your assembly. It will have all your options and same DLL files loaded. Saves a good chunk of time if you’re going to do this frequently.

If all goes well, this will give you your secured combined assembly.
Remove the original DLL from the zip file and replace it with the secured one.
Remove the Reference file (or whatever it’s called).
Make sure you leave the original .cs and info.xml files intact.

The final zip file should include only the following three items:
info.xml
YourPackage.cs
YourPackage.dll

Import this on a 3rd system and test.

Hope this helps.

3 Likes

Thanks for the indepth information. I will give it a go and hope it resolves the issue.