• 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

  • reach4thelasers
    replied
    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.

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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.

    Leave a comment:


  • reach4thelasers
    replied
    sorry forgot to attach... small project that shows the issue
    Attached Files

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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.

    Leave a comment:


  • reach4thelasers
    replied
    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.

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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

    Leave a comment:


  • reach4thelasers
    started a topic IBar - TypeInitialization Problem

    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??

Latest Posts

Collapse

Topics Statistics Last Post
Started by evanp90, Today, 12:32 PM
0 responses
2 views
0 likes
Last Post evanp90
by evanp90
 
Started by camtrading, Today, 11:50 AM
2 responses
11 views
0 likes
Last Post camtrading  
Started by emuns, Today, 11:55 AM
0 responses
5 views
0 likes
Last Post emuns
by emuns
 
Started by voltation, Today, 12:58 AM
4 responses
27 views
0 likes
Last Post voltation  
Started by lakersfan, Today, 11:36 AM
1 response
6 views
0 likes
Last Post NinjaTrader_SergeyS  
Working...
X