• 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

Serializing with the same code gives different results in NT vs VS.

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

    Serializing with the same code gives different results in NT vs VS.

    My setup:
    Win10 Home, lang=Swedish, NT8.0.16.3, VS2017, .NET4.7

    Problem:
    When serializing and deserializing (a custom type/list = PriceBars : IList<PriceBar>) with the bellow code (targeting .NET 4.7) in VS2017 everything works fine.
    When serializing the same type/list with the exact same code in NT8 I get an exception when deserializing it in the same VS project as above.

    Exception:
    system.runtime.serialization.serializationexceptio n: unable to find the assembly d04d3a...... version 8.0.16.3, Culture=neutral... (se encl pic)

    Question:
    The serializer namespace resides in System.Core.Dll. But the thrown exception refers to an strange assembly with a version number identical the the NT8 version. Any clue what´s going on here? Is NT8 referencing a different System.Core.Dll assembly than VS2017?

    private void ToBinFile(PriceBars priceBars)
    {
    // paths
    string folderPath = System.Environment.GetFolderPath(Environment.Speci alFolder.MyDocuments);
    string filePath = folderPath + @"\NTprices2.cfe";

    // Open a stream for writing.
    FileStream fs = new FileStream(filePath, FileMode.Create);

    // Construct a BinaryFormatter
    BinaryFormatter bf = new BinaryFormatter();
    try
    {
    bf.Serialize(fs, priceBars);
    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    throw;
    }
    finally
    {
    fs.Close();
    }
    }

    Click image for larger version

Name:	EX.jpg
Views:	1
Size:	138.1 KB
ID:	1046384
    Caption


    #2
    I just realized the reason might be that the serialized object recides in different namespaces when serialized and deserialized.

    Comment


      #3
      Hello FREEN,

      Thank you for the post.

      I just wanted to confirm, had you solved your question? Based on your reply it seems that you potentially have however if you still have further questions please feel free to update the post.

      In regard to a difference between VS and NT, you will generally see differences between these programs because NinjaTrader is physically compiling the code and references you have added opposed to visual studio compiling the code and references.

      NinjaTrader is also using .net 4.5, not 4.7. If you have created a custom project in visual studio, you would be able to pick and choose the framework or references used so the code used in VS may not directly work in NinjaTrader depending on the syntax used and references used. Generally, you would instead want to click the VS button from the NinjaScript editor and open that project, this will configure VS correctly for NinjaTrader and include the correct references. you should not need to modify the VS project at all to have it match NT.

      If you instead wanted to make a custom project of your own in VS, please see the addon sample we provide in the help guide here: https://ninjatrader.com/support/help...t_overview.htm (AddOn Development Environment (Visual Studio Advanced)). This project has the correct paths/.net/build events to create a NinajTrader compatible DLL.


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Thanks Jesse,

        You gave me more info than I knew I needed, thanks! I´ll study the best practices for custom dll´s.

        Kindly, Fredrik

        Comment


          #5
          How my problem got solved:
          1: Built a VS library project containing the classes used both in NT and VS.
          2. Referenced the exact same dll from both NT and VS.

          This made it possible to extract marketdata with NT, write (serialize) to binary file, open (deserialize) the file in VS project for further handling.

          Conclusion:
          Even though the my classes initially recided in the same namespace with the exact same code (the deserializing beeing done with code reciding in a VS Project), they rather had to reference the exact same dll library containing the classes. The reason for this is unclear to me.
          Last edited by FREEN; 02-25-2019, 03:41 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by xsgex, Yesterday, 09:46 PM
          0 responses
          2 views
          0 likes
          Last Post xsgex
          by xsgex
           
          Started by Steve L, Yesterday, 09:36 PM
          0 responses
          1 view
          0 likes
          Last Post Steve L
          by Steve L
           
          Started by krugman25, Yesterday, 09:34 PM
          0 responses
          4 views
          0 likes
          Last Post krugman25  
          Started by indy73, Yesterday, 04:42 PM
          0 responses
          15 views
          0 likes
          Last Post indy73
          by indy73
           
          Started by Italianforex, Yesterday, 06:20 AM
          2 responses
          13 views
          0 likes
          Last Post gplatis
          by gplatis
           
          Working...
          X