Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Adding References (From Visual Studio)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PaulMohn
    replied
    Hello Jesse,

    To use external references you would need to acquire the .dll files and any other files that go with the library in question and place them into the Documents\NinjaTrader 8\bin\Custom folder.
    How do I know which ones of other files to add that go with the .dll?

    I'm trying to get this Nuget package content into the NT8 Custom folder
    MathNet.Numerics

    (I've downloaded version 4.15.0 from the page/no visual studio)

    The root folder Content
    C:\Users\user\Desktop\New folder (8)\_rels
    C:\Users\user\Desktop\New folder (8)\lib
    C:\Users\user\Desktop\New folder (8)\package
    C:\Users\user\Desktop\New folder (8)\.signature.p7s
    C:\Users\user\Desktop\New folder (8)\[Content_Types].xml
    C:\Users\user\Desktop\New folder (8)\icon.png
    C:\Users\user\Desktop\New folder (8)\MathNet.Numerics.nuspec
    Click image for larger version  Name:	7zFM_L7RnxOY2NS.png Views:	0 Size:	38.9 KB ID:	1193175
    The lib folder content
    C:\Users\user\Desktop\New folder (8)\lib\net40\MathNet.Numerics.dll
    C:\Users\user\Desktop\New folder (8)\lib\net40\MathNet.Numerics.xml
    Click image for larger version  Name:	chrome_NEOpZTJEu0.png Views:	0 Size:	30.9 KB ID:	1193174
    The package folder content
    C:\Users\user\Desktop\New folder (8)\package\services\metadata\core-properties\2a33219537e2439e9b6680f04f051bed.psmdcp
    Click image for larger version  Name:	7zFM_sAbGh1iri8.png Views:	0 Size:	28.0 KB ID:	1193173
    the .rels folder content
    C:\Users\user\Desktop\New folder (8)\_rels\.rels
    Click image for larger version  Name:	7zFM_mc69cIqf8w.png Views:	0 Size:	25.1 KB ID:	1193172
    Thanks!
    Last edited by PaulMohn; 03-10-2022, 08:20 AM.

    Leave a comment:


  • Zeero
    replied
    It worked! Thank you I've been looking at both these issues for many hours and could not figure them out.

    Sorry about the namespace name. I changed it in my post to attempt to make it simpler to read.

    ​​​​​​​You have been most helpful NinjaTrader_Jesse

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Zeero,

    Edit: I think I may see the problem, the dll needs to go in the folder bin/Custom and you have used bin/custom/references. All dlls need to be in the root bin/custom folder. you will need to remove the reference from the NinjaScript editor, close NinjaTrader and then move the file and re reference it.


    From the given details that sounds correct, I am not seeing anything missing here. I can see that you are using a same name class/namespace so accessing that would instead look like:

    Code:
    Print(PeakFinder.PeakFinder.test());
    That shouldn't cause the error you are reporting though if you failed to access it correctly, it would look like:
    The type or namespace name 'test' does not exist in the namespace 'PeakFinder' (are you missing an assembly reference?)
    I would likely suggest to try making the class in the same namespace as the type you are using to make it easy to reference/use for example placing your class in the namespace namespace NinjaTrader.NinjaScript.Indicators would result in using it like the following with no added using statements:
    Code:
    Print(PeakFinder.test());
    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class PeakFinder
        {
            public static string test()
            {
                return "Got to the method";
            }
        }
    }

    I can see this working on my end, the steps were as you wrote:
    compile from VS
    Copy DLL to bin/custom folder
    Reference DLL in NinjaTrader
    Compile
    Use code in your script


    If you cant get it working could you try to zip the project and attach it? I don't believe you can attach files with dlls here so clearing the debug folder before you attach it may be required.


    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 12-31-2019, 01:11 PM.

    Leave a comment:


  • Zeero
    replied
    Problem:

    I Get errors when importing and trying to use `.dll` files in `NinjaTrader`. I don't get this same error when importing the .dll into a Visual Studio code project and running a unit test on one of the methods.

    How To Reproduce Issue:

    Create a new `library` project in `Visual Studio` that uses `.NET Framework 4.5`. Build the project and this creates a `dll` in my `Debug` folder for the project. Use the following code for the project

    Code:
    using System;
    
    namespace PeakFinder {
    
        public class PeakFinder {
    
            public static string test() {
                return "Got to the method";
            }
        }
    }
    Move the `.dll` into `NinjaTrader 8\bin\Custom\references`. Opening the `references` menu in `NinjaTrader` add the `.dll`. Create an `indicator` that
    Code:
    using PeakFinder;
    and calls the following
    Code:
    wasPeak2BarsAgo = PeakFinder.test();
    Open a chart and go to the menu to add an indicator and an error message like the following should show up.
    Indicator 'aaYourIndicator': Error on calling 'OnStateChange' method: Could not load file or assembly 'PeakFinder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
    Questions:

    Is there something in this process I'm doing wrong?
    My project doesn't feel like it has much in dependencies why can it not load the assembly?
    Last edited by Zeero; 12-31-2019, 12:42 PM.

    Leave a comment:


  • Zeero
    replied
    NinjaTrader_Jesse Thank you for the amazing reply. That answers my question in full.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Zeero,

    The reason you are seeing that the platform cannot find the reference and also why when you open the project the references have changed is that NinjaTrader is re-generating the .csproj on its own.

    When using visual studio with NinjaTrader you will not be able to use many of the features in visual studio directly. It mainly is just a text editor in contrast to NinjaScript. You cannot use nuget or compile from visual studio because NinjaTrader is managing the solution and is in charge of compiling/adding references.

    To use external references you would need to acquire the .dll files and any other files that go with the library in question and place them into the Documents\NinjaTrader 8\bin\Custom folder. Finally you need to use the NinjaScript editors Right click -> References menu to add the references. Once you add references you can compile from inside of NinjaTrader to update the visual studio project.



    If you are using nuget to get the package, you could make an external visual studio .net 4.5 project (not the ninjascript project from the editor) and add the nuget package to it. Finally build the project to collect the dll's from the output folder likely bin/debug. You can delete the project after collecting the files you needed you just need to copy them to the NinjaTrader user folder bin/Custom directory. Otherwise you can look on the developers website/github or wherever is linked with the package you are trying to use to see if manual downloads are available. You need .net desktop 4.5 or less for the package.



    I look forward to being of further assistance.

    Leave a comment:


  • Zeero
    started a topic Adding References (From Visual Studio)

    Adding References (From Visual Studio)

    Problem (What actually happens)

    When using Visual Studio I can `Add References` or install a `Nuget` Package. In my editor there are no red underlines when I am `using` these packages. This suggests that the package is resolving correctly. When I compile in NinjaTrader it can not find said package.

    Another interesting thing is that the package looks resolved until `NinjaTrader` is opened again then the packages `reference` is not longer available and all imports are not working in `Visual Studio` as well.

    Expected

    I would have thought I could install `Nuget` Packages from `Visual Studio` and used them while compiling in `NinjaTrader`.

    Question

    My question is how can I bring in an external package (.dll library) into my project for code use?

Latest Posts

Collapse

Topics Statistics Last Post
Started by judysamnt7, 03-13-2023, 09:11 AM
4 responses
59 views
0 likes
Last Post DynamicTest  
Started by ScottWalsh, Today, 06:52 PM
4 responses
36 views
0 likes
Last Post ScottWalsh  
Started by olisav57, Today, 07:39 PM
0 responses
7 views
0 likes
Last Post olisav57  
Started by trilliantrader, Today, 03:01 PM
2 responses
21 views
0 likes
Last Post helpwanted  
Started by cre8able, Today, 07:24 PM
0 responses
9 views
0 likes
Last Post cre8able  
Working...
X