How to Resolve NinjaScript Errors

NinjaTrader compiles every NinjaScript file on your PC together, so a single file with a programming error blocks all of them. Until it is fixed, NinjaTrader will not import, update or remove add-ons, and you cannot create or edit strategies. This guide shows how to find the file causing it and how to clear the most common errors.
You will usually see one of these messages:
- “Import failed. This NinjaScript Archive File may contain duplicate method names that already exist on your PC, modify a method signature that other scripts were dependent on, or be missing a required file on either your PC or in the import archive.”
- “You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before you can import a NinjaScript Archive File.”
- “Remove failed. You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before removing a NinjaScript assembly.”
- “NinjaTrader must be in a compilable state to create or edit Strategies. Please use the NinjaScript editor to resolve compilation errors.”
- “Unhandled exception: Could not find a part of the path ‘X/NinjaTrader 8/tmp/Import/Backup.”
Errors While Importing or Updating an Indicator
If an import fails, installing the files by hand almost always works. Follow every step in order:
- Open the download: double-click the zip file in File Explorer.
- Copy the
.csand.dllfiles out of the zip onto your desktop. - Move them into NinjaTrader’s Custom folder:
- Open
Documents > NinjaTrader 8 > bin > Custom. - Drag the
.csand.dllfiles from your desktop into that folder. If you are updating, choose Yes to replace the existing files. - Put them directly in the Custom folder, not in a folder inside it.
- Open
- Restart NinjaTrader.
- Check that it worked: open a chart, right-click it, choose Indicators and look for the indicator in the list.
Note: you do not need to import the indicator again afterwards. These steps install it.
OneDrive Related Issues
Microsoft OneDrive is the most common cause of NinjaScript errors. If your NinjaTrader 8 folder sits in a location OneDrive manages, start with our guide:
Resolving NinjaTrader Desktop Issues With Microsoft OneDrive
NinjaTrader compiles all of your indicators and strategies in one pass instead of one at a time, which is why one broken file holds up the rest. The usual causes are an add-on whose reference to a .dll file is missing, a reference that still points at an old file location, or two copies of the same file that define the same thing twice.
Find the Compile Error That Is Blocking NinjaTrader
If you already know the error code, skip to it below. If not, find it like this:
- In the NinjaTrader Control Center, open New > NinjaScript Editor. It can take a few seconds to appear.
- Right-click anywhere in the editor and choose Compile (or press F5).
- Watch the bottom-left corner: a loading icon shows while it compiles. If it finishes with a chime and no errors are listed, your NinjaScript compiles cleanly and your add-ons work normally.
- Otherwise the errors are listed in orange at the bottom of the editor. Each one names the file, the error code and a description. These must be fixed, or the file excluded (see below), before you can import or remove add-ons, and some add-ons will not work correctly until then.
An error line names the file, the code and the problem, for example:
ExampleAssembly.cs CS0006 Metadata file 'ExampleAssembly.dll' could not be found
Common Compile Errors and How to Fix Them
Start with the errors below. Clearing them often clears the rest of the list too.
CS0006 – “Metadata file ‘example.dll’ could not be found”
What it means: an add-on refers to a .dll file that NinjaTrader cannot find on your PC.
How to fix it:
- Right-click inside the NinjaScript Editor and choose References.
- Select the reference to the .dll named in the error.
- Click Remove.
- Click OK and compile again.
NinjaTrader’s video walks through it: Metadata File Not Found
CS0246 – “The type or namespace name ‘exampleassembly’ could not be found (are you missing a using directive or an assembly reference?)”
What it means: NinjaTrader is looking for a reference to a .dll file that it cannot locate.
How to fix it:
- Right-click inside the NinjaScript Editor and choose References.
- Click Add.
- Browse to the .dll for the file named in the error and click Open.
- Click OK and compile again.
This also clears the CS0118 error that often appears just below CS0246. NinjaTrader’s video: Missing Assembly or Reference
CS0234 – “The type or namespace name ‘exampleindicator’ does not exist in the namespace ‘examplelocation’ (are you missing an assembly reference?)”
What it means: one of NinjaTrader’s own built-in indicators is missing from Documents > NinjaTrader 8 > bin > Custom > Indicators, or a file there is corrupt.
How to fix it:
- Close NinjaTrader.
- Open the Windows Control Panel from the Start menu. The Windows Settings app does not have this option.
- Go to Programs > Programs and Features.
- Select NinjaTrader in the list and click Repair. This replaces missing or damaged NinjaTrader files without changing your settings.
- Restart NinjaTrader and compile again.
NinjaTrader’s video: Resolving the Indicator is Missing or Corrupted Message
Exclude the File With the Error From Compilation
If an error points at an add-on you do not need right now, you can leave its file out of the compile instead of fixing it, so the rest of your NinjaScript compiles and imports work again:
- Compile in the NinjaScript Editor and note the file named in the orange error at the bottom of the window.
- On the right side of the NinjaScript Editor, double-click the folder for that object type (for example, Indicators) to expand it.
- Left-click the file to select it, then right-click it.
- Select Exclude From Compilation, then compile again. From the same menu, Open lets you debug the file instead, and Remove deletes it.
An excluded add-on is not available in NinjaTrader until you include it in compilation again.
Resolving Uncommon Compile Errors
For any other error code, NinjaTrader’s Desktop Help Guide lists every documented compile error and its fix: Compile Error Codes
If the code is not listed there, contact the developer of the add-on named in the orange error. If the error is in a NinjaScript you wrote yourself and it is not documented, contact NinjaTrader support, who can pass it to their NinjaScript Engineering team.
If the error names one of our add-ons, contact our support team and we will help you clear it.