• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IBar - TypeInitialization Problem

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

    IBar - TypeInitialization Problem

    I've wasted the morning trying to fix this weird issue related to implementing the NinjaTrader.Core.Data.IBar type for my unit testing. I've attached a very simple VS project.

    I've stripped it back to a basic concrete class and a two line test method and I'm at a loss to explain the error.

    public class MyBar : IBar
    {
    public double Close { get; }
    public bool FirstBarOfSession { get; }
    public double High { get; }
    public double Low { get; }
    public double Open { get; }
    public DateTime Time { get; }
    public long Volume { get; }
    }
    [TestMethod]
    public void TestMethod1()
    {
    IBar bar = new MyBar();
    var close = bar.Close;
    }


    Error:

    Test method IBarTypeInitProblem.Test.TestMethod1 threw exception:

    System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.ArgumentNullException: Value cannot be null.

    Parameter name: ptr
    at System.Runtime.InteropServices.Marshal.GetDelegate ForFunctionPointer(IntPtr*ptr,*Type*t)
    at <CliSecureRT>.InitializeThroughDelegate(IntPtr)
    at <CliSecureRT>.Initialize()
    at .cctor()
    --- End of inner exception stack trace ---
    at IBarTypeInitProblem.Test.TestMethod1()



    remove the var close = bar.Close line and no error. Add it and it throws an exception before then. Any Ideas??

    #2
    Hello reach4thelasers,

    Thank you for your post.

    Can you call any other values? Such as bar.High or bar.Time?
    Or do they return the same exception?

    You can also look into using Try-Catch blocks to hopefully further isolate the matter: http://ninjatrader.com/support/forum...ead.php?t=9825
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I use try catch blocks throughout my code - they didn't catch this. If I pass an IBar into the constructor of another class, the exception fires before the class constructor is entered, but only if I reference one of the properties defined in the IBar interface. I've been programming .NET C# for years but this has got me stumped.

      Comment


        #4
        Hello reach4thelasers,

        Thank you for your response.

        Do you have a script I could test this with?
        Last edited by NinjaTrader_PatrickH; 09-03-2015, 09:54 AM.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          sorry forgot to attach... small project that shows the issue
          Attached Files

          Comment


            #6
            Hello reach4thelasers,

            Thank you for your response.

            There is no bar to pull the objects from and you are not returning anything for get.

            The error you get I do not. However, I do receive errors. These errors indicate that there is not object being pulled and thus no information for your test method.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              The point of an interface is that I can make my own implementation of a bar "MyBar" that looks like a bar and acts like a bar but doesn't require me to be connected to the Ninjatrader application or servers.... It means that I can write code for consuming a bar without needing to connect and pull live data

              Simple types like double, int and bool are value types and default to zero if not defined. Properties declared as {get; } without a backing field are automatic properties - they can still be set from the constructor of the class - which is what I was doing before I stripped it back, never the less they should be returning zero.

              Strange that you don't get the error.... doesn't matter I went with my own type Candle/ICandle which lets me add more functionality anyway.

              Thanks for looking at it.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by dadarara, Today, 12:18 PM
              0 responses
              2 views
              0 likes
              Last Post dadarara  
              Started by joemiller, Today, 07:33 AM
              0 responses
              7 views
              0 likes
              Last Post joemiller  
              Started by isnercrypto, Today, 06:42 AM
              0 responses
              4 views
              0 likes
              Last Post isnercrypto  
              Started by Coursocied67, Today, 04:02 AM
              0 responses
              5 views
              0 likes
              Last Post Coursocied67  
              Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
              7 responses
              37 views
              0 likes
              Last Post DaveS
              by DaveS
               
              Working...
              X