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

SeDes for Serialize & Deserialize

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

    SeDes for Serialize & Deserialize

    Hello everyone
    I need help please

    I am trying to serialize and deserialize but I get this error:

    Failed to deserialize. Reason: Unable to find assembly '7f5f4c78bfdb4af6bf14f7058910a2b1, Version=8.0.23.0, Culture=neutral, PublicKeyToken=null'.

    Thanks
    M.GHORBEL
    Attached Files
    Last edited by MGHORBEL; 11-12-2020, 01:54 AM.

    #2
    Hello MGHORBEL,

    Thank you for the post.

    I took a look at the attached file and it seems that the cast to your custom object in the deserialization is the problem, the type is not able to be found in that context. Unfortunately using serialization is outside of what our support can directly assist with, I can try to gather more details here to see if there is some solution for your use case.

    Do you specifically need binary serialization or would any serialization work? Generally items that save data will do so as text or strings, that could include other type of formatting like json.
    Also are you trying to serialize an object with your strategies states/workspace? If so a public property can be used in that use case instead of custom serialization. The property would need to make whatever data is to be saved into a string in that use case.


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

    Comment


      #3
      Hello NinjaTrader_Jesse
      Thank you for your reply

      In fact I used this example to illustrate my need to save data.

      My need is to save data in any form. The main thing for me is to save, and then download them.

      My need concerns the data and the architecture of a neural network. (I don't neet to save strategies states/workspace. )

      I tried several times and for several weeks to find a solution.

      Can you please give me an example of saving then downloading the data?

      M.GHORBEL

      Comment


        #4
        Hello MGHORBEL,

        Thank you for the clarification. In this case you may need to try other C# methods of serialization from different namespaces, I am unaware of an existing example using binary serialization.

        The standard way to serialize data is simply to make a public property in your scripts class however that system works with the platforms saving, for example when you save the workspace. For manual serialization you can find examples of C# ways to do that in external resources. You could try using a json serializer instead to see if that is able to work. The binary formatter is trying to locate the class you made however it would not be able to do that in the NinjaTrader.Custom context. For downloading data you can see the following news indicator which has an example of downloading data. This is not a NinjaScript concept but just a C# concept so this is not something our support or documentation can help with. https://ninjatraderecosystem.com/use.../jteconnews2a/

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.


        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          If you need JSON serialization / deserialization, the following code worked for me in NT 8. Here is the solution that works for me:

          Code:
          using System.Web.Script.Serialization;
          
          public T DeserializeJson<T>(string Json)
          {
              JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();
              return JavaScriptSerializer.Deserialize<T>(Json);
          }
          
          public string SerializeJson<T>(T Obj)
          {
              JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();
              return JavaScriptSerializer.Serialize(Obj);
          }​
          See official MS docs at https://learn.microsoft.com/en-us/do...ramework-4.8.1
          Last edited by skipper-flatiron-18; 08-30-2023, 08:20 AM.

          Comment


            #6
            Hi skipper-flatiron-18

            Thank you
            for your help.

            I find this code in the net and then I used it.


            Have a nice day


            CODE :

            using System;
            using System.Collections.Generic;
            using System.IO;
            using System.Xml.Serialization;


            namespace GenericSerialize
            {

            class SimpleClass
            {

            const string FileSavePath = @"c:\data\SimpleClass.xml";

            public Guid ID { get; set; }
            public string CityName { get; set; }
            public int Rank { get; set; }
            public bool Active { get; set; }
            public List<string> RandomList { get; set; }

            public SimpleClass()
            {
            ID = Guid.NewGuid();
            RandomList = new List<string>();
            }

            public void BasicSave()
            {
            var xs = new XmlSerializer(typeof(SimpleClass));
            using (TextWriter sw = new StreamWriter(FileSavePath))
            {
            xs.Serialize(sw, this);
            }
            }

            public void BasicLoad()
            {
            var xs = new XmlSerializer(typeof(SimpleClass));
            using (var sr = new StreamReader(FileSavePath))
            {
            var tempObject = (SimpleClass)xs.Deserialize(sr);
            ID = tempObject.ID;
            CityName = tempObject.CityName;
            Rank = tempObject.Rank;
            Active = tempObject.Active;
            }
            }

            public bool SaveGeneric1(string fileName)
            {
            return GenericUtils.Save<SimpleClass>(fileName, this);
            }

            public void LoadGeneric1(string fileName)
            {
            var fileData = GenericUtils.Load<SimpleClass>(fileName);
            ID = fileData.ID;
            CityName = fileData.CityName;
            Rank = fileData.Rank;
            Active = fileData.Active;
            }


            public bool SaveGeneric2(string fileName)
            {
            return GenericUtils.Save2(fileName, this);
            }

            public void LoadGeneric2(string fileName)
            {
            var obj = GenericUtils.Load2(fileName);
            // TODO .. show implement of reflection call to deep copy object onto self
            }

            }


            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            22 views
            0 likes
            Last Post trilliantrader  
            Started by Davidtowleii, Today, 12:15 AM
            0 responses
            3 views
            0 likes
            Last Post Davidtowleii  
            Started by guillembm, Yesterday, 11:25 AM
            2 responses
            9 views
            0 likes
            Last Post guillembm  
            Started by junkone, 04-21-2024, 07:17 AM
            9 responses
            70 views
            0 likes
            Last Post jeronymite  
            Started by mgco4you, Yesterday, 09:46 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X