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

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:	177
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 yertle, Yesterday, 08:38 AM
          7 responses
          28 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by bmartz, 03-12-2024, 06:12 AM
          2 responses
          21 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          4 views
          0 likes
          Last Post funk10101  
          Started by gravdigaz6, Yesterday, 11:40 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X