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

Can not use custom .dll

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

    Can not use custom .dll

    Hello

    I created my custom .dll (see attachment)
    It is very simple - just 1 interface and 1 form, nothing more.
    I built this project and copy the .dll file into
    D:\Users\Marek Lorenc\Documents\NinjaTrader 7\bin\Custom
    Then I opened my indicator source code where I want to use this my custom classes,
    and add reference and browse the .dll file.

    When I type using HladinaLibrary; it is working and I can compile.
    But I can not use any class and interface from the library.. why?

    The .dll file is in correct path, I added the reference and I used the using HladinaLibrary; and the classes inside of HladinaLibrary are public. So what is wrong? I dont understand

    Thank you

    #2
    Hello zooinek,

    Thank you for your post.

    You've checked the things we'd have you check here, and unfortunately don't have more to offer. If you can send the file, I'll take a look at it. You can post here or send to [email protected]
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      sorry I forgot to add the attachment
      here it is. ...it's complete VisualStudio solution... but dont worry as I said.. it's just one interface and one form
      Attached Files

      Comment


        #4
        zooinek, did you restart NT after copying in the file and adding the reference?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I also have the same problem with NT7.
          Compiled an external dll for testing and when I trying to use it within the indicator nothing works!

          Comment


            #6
            Do you get any errors? Is it copied in the bin > custom folder and then you did a fresh restart of NT so actually loaded up?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Restart magically helped :-)

              Tx!

              Comment


                #8
                Great, thanks for letting us know!
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Cannot instantiate custom class in NT Strategy or Indicator

                  Hi,

                  I am experiencing this same problem and followed the same steps, but I did not have success resolving this. I am trying to instantiate a custom class instance inside an indicator or strategy. I do the following steps:

                  1) create a windows library application in Visual Studio 2010. All classes and methods I am using are public and there is no signing of the namespace.

                  2) compile to a .dll called TradingObjectTest.dll

                  3) move the .dll to the C:\Documents and Settings\1\My Documents\NinjaTrader 7\bin\Custom

                  4) Create a new indicator called MyCustomIndicator just using the default indicator creation tools in NT

                  5) Add a reference to the .dll which in this case is called TradingObjectTest.dll

                  6) add a using statement at the start of the indicator "using TradingObjectTest"

                  7) The TradingObjectTest name space has a public class called SimpleBarObject() with a default constructor so no parameters are required. All SimpleBarObject does is hold bar data such as a high, low, open, and close value. The point of this is just to test if I can instantiate any custom class in a Ninja Trader Strategy so I am not looking for other ways to use bar data, just to test the ability to instantiate a custom class instance.

                  8) The indicator compiles just fine.

                  9) Restart Ninja Trader

                  10) Open a market replay connection and move to a date where there is some data to work with

                  11) Add the Custom Indicator to the chart

                  12) In the output window I get the following error:

                  Failed to call method 'Initialize' for indicator 'MyCustomIndicator': Could not load file or assembly 'TradingObjectTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

                  It is as though it accepts the reference at compile time, but can't find the name space at run time. Why would this be happening? I don't understand why it would compile and then lose the reference? I am finding this to be a really frustrating problem. It seems like it should work if it compiles right?

                  I am attaching all the related code so that you can follow everything I did. I attached the MyCustomIndicator.cs as well as the Visual Studio Project so anyone can compile it along with the dll. You will see that besides the classes I wrote in the namespace I am only using one other using clause which is System.Collections so I can use ArrayLists. This dll is available in the NT Indicator normally and is used in several indicators like the swing indicator so don't know why that would cause it to fail. Thank you for any assistance.

                  Garth Gerstein
                  Attached Files
                  Last edited by ggerstein; 05-02-2012, 06:05 PM.

                  Comment


                    #10
                    ggerstein, what target framework is your custom dll compiled / created for? .NET 3.5?
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Target Framework

                      Yep.That is correct 3.5. That is what I should target for NT 7. Is that a correct understanding?

                      I just realized I may not have zipped up the correct thing. This is the entire solution folder that can be imported into VS 2010 or later so you will able to see the target framework and settings. I had two projects in the solution. One is a console application that acts as a test driver so I can validate the library code outside NT. This may be easier and you can see the code run independent of NT. Thank you again for any insight.
                      Attached Files
                      Last edited by ggerstein; 05-03-2012, 06:23 PM. Reason: Added file and elaborated.

                      Comment


                        #12
                        Seeing the same outcome in testing here, if I check into your settings file on my end I see 4.0 as target framework - this is very likely the issue you see. Please recheck on a 3.5 compatible dll.

                        (error seen in trace confirms this - 'System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\user\Documents\NinjaTrader 7\bin\Custom\TradingObjectTest.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
                        File name: 'file:///C:\Users\user\Documents\NinjaTrader 7\bin\Custom\TradingObjectTest.dll'')
                        Last edited by NinjaTrader_Bertrand; 05-07-2012, 02:25 AM.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Thank you Bertrand. I tested this out and you were correct. It was the target framework that was causing the problem. Seems to be working now which is a relief. I have a follow up question though. How did you get the trace for that error? The only debugging capability I seem to have in NT is the output window which is hugely frustrating because often the errors are very vague. Is there another debugging approach that I can use to get the level of detail on the error that you got? In my case it did not mention any thing regarding the target framework so I didn't even know where to start looking for this. If you have any suggested or more effective debugging strategies for NT I would really appreciate it.

                          Better yet, would it be possible to run NT inside Visual Studio in some way so you could step through code? Don't even know if that is possible, but really curious.
                          Thank you.

                          ggerstein
                          Last edited by ggerstein; 05-06-2012, 03:50 PM.

                          Comment


                            #14
                            Glad to hear the correct target framework helped resolve the loading issue - are you already aware of those debug assist steps?

                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Hey Bertrand,

                              Yes, I did find these after I posted. I actually remember coming across this a long time ago, but the reason I didn't use them at the time is because I only had the express version of VS. I have gone ahead and purchased a full version and will try this. It is too painful to try to do what I am doing with try catch blocks and way too much of a waste of time so I will try this route and hopefully the method works well to really find where scripts are failing. Thank you for your assistance in resolving this issue.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by SnailHorn, Today, 10:49 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post SnailHorn  
                              Started by naanku, Today, 07:25 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post naanku
                              by naanku
                               
                              Started by milfocs, Today, 07:23 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post milfocs
                              by milfocs
                               
                              Started by PaulMohn, Today, 06:59 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post PaulMohn  
                              Started by bortz, 11-06-2023, 08:04 AM
                              48 responses
                              1,756 views
                              0 likes
                              Last Post carnitron  
                              Working...
                              X