Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT 8.0.24.0 vs Json

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

    NT 8.0.24.0 vs Json

    NinjaTrader 8.0.24.0 seems to have changed something related to Json.

    I have some simple Json code (10 lines) which was working under 8.0.23.2 but now in 8.0.24.0 fails to compile with a variety of errors. The code has been stable for a long time and has not changed. Commenting out the code makes the compilation work.

    Here is a list of the errors:
    Code:
     [TABLE="width: 1123"]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The type 'System.IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The type 'System.IO.TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The best overloaded method match for 'Newtonsoft.Json.JsonTextWriter.JsonTextWriter(Sys tem.IO.TextWriter)' has some invalid arguments[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]Argument 1: cannot convert from 'System.IO.StreamWriter' to 'System.IO.TextWriter'[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]'Newtonsoft.Json.JsonWriter': type used in a using statement must be implicitly convertible to 'System.IDisposable'[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The type 'System.IO.TextReader' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The best overloaded method match for 'Newtonsoft.Json.JsonTextReader.JsonTextReader(Sys tem.IO.TextReader)' has some invalid arguments[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]Argument 1: cannot convert from 'System.IO.StreamReader' to 'System.IO.TextReader'[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The type 'System.Type' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]The best overloaded method match for 'Newtonsoft.Json.JsonSerializer.Deserialize(Newton soft.Json.JsonReader, System.Type)' has some invalid arguments[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]Argument 2: cannot convert from 'System.Type [c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ms corlib.dll]' to 'System.Type'[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [TR]
    [TD][SIZE=15px][COLOR=black][FONT=Calibri]'Newtonsoft.Json.JsonReader': type used in a using statement must be implicitly convertible to 'System.IDisposable'[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
    [/TABLE]
    It seems a reference or dll has changed.

    I have a reference to C:\Program Files (x86)\NinjaTrader 8\bin64\Newtonsoft.Json.dll and up until this release this has been all that was needed.

    Grateful for advice on getting this compilation to behave correctly.

    Thanks.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Hello jeronymite,

    Do you know what version of .NET this assembly is targeting?

    There was an upgrade of .NET to 4.8 in 23.2 that could be the culprit.
    https://ninjatrader.com/support/help...8/8_0_23_2.htm

    Can you remove and add new references? (Especially to netstandard)

    What does the method signature show?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your assistance.

      The code worked in 8.0.23.2. It is only in 8.0.24.0 that it fails to compile.

      There are two small methods of a mere few lines each:
      Code:
      public static void JsonWrite<T>(T pSourceObject, string pFilename)
      public static void JsonRead<T>(ref T pTarget,string pFilename)
      They compiled and worked as expected in 8.0.23.2.

      Thanks.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        Hello jeronymite,

        May I have a screenshot of the errors showing that these are the wrong object types?

        I'm unfamiliar with these object types but I can check to see if they match.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Chelsea.

          My original post above has the full set of errors for both methods, the first 6 errors being for the method below. The errors are not on the signatures but the code itself.

          Here's one of the methods:
          Code:
          // --- Write a Json serialization file ---
          public static void JsonWrite<T>(T pSourceObject, string pFilename)
          {[INDENT]Newtonsoft.Json.JsonSerializer sarp = new Newtonsoft.Json.JsonSerializer();
          using (StreamWriter sw = new StreamWriter(pFilename))[/INDENT][INDENT=2]using (Newtonsoft.Json.JsonWriter jjw = new Newtonsoft.Json.JsonTextWriter(sw))
          {[/INDENT][INDENT=3]sarp.Serialize(jjw, pSourceObject);[/INDENT][INDENT=2]}[/INDENT]
           }
          The first 6 errors were generated when compiling this method. The first error is on the "sarp" declaration, the other 5 on the "using ... JsonWriter ..." statement.

          Hope this is sufficient to analyse and identify the issue.

          Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            Hello jeronymite,

            Typically errors have filenames and line numbers.

            This is all the information you are getting from the error?

            (This might indicate the error is not in your script but instead something with a reference and no assembly files)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              The errors are "normal" in nature, and what I have provided is just the error portion, but I added in the explanation above the lines affected. The module is nearly 4K lines long, so I extracted the method, the error messages, and identified the lines that generated those messages.

              I have attached a screenshot that shows exactly that.

              Thanks.
              Attached Files
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment


                #8
                Hello jeronymite,

                We have reported that the Json Dll included in R24 is not compatible with .NET 4.8 It was included for a new connection adapter, and Product Management is discussing with Development how to move forward.

                We will keep you posted.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Thanks, Jim. I appreciate the update.

                  In the meantime, I have implemented an alternative approach using System.Text.Json.JsonSerializer that seems to work well.

                  Thanks.
                  Multi-Dimensional Managed Trading
                  jeronymite
                  NinjaTrader Ecosystem Vendor - Mizpah Software

                  Comment


                    #10
                    Hello jeronymit,

                    Thank you for providing your workaround.

                    Our development has this under review and this issue is being tracked with ID# NTEIGHT-14868.

                    In the meantime, it would also be possible to add the .NET 4.5 assembly to the Documents/NinjaTrader 8/bin/Custom/ folder and add a reference.
                    Newtonsoft.Json.11.0.2 - https://drive.google.com/file/d/19m_...ew?usp=sharing
                    Adding a reference - https://ninjatrader.com/support/help...indicators.htm

                    When exporting your custom script, be sure to include a reference to the Newtonsoft.Json assembly.
                    https://ninjatrader.com/support/help...netReferencing

                    Also, manually add the Newtonsoft.Json.dll file to the export.zip (drag and drop it in the .zip to add it).
                    Attached Files
                    Last edited by NinjaTrader_ChelseaB; 06-08-2021, 02:07 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Still no resolution?

                      System.Text.Json would seem to be a good work around.

                      How would one add System.Text.Json to work around? It is missing in the default setup.

                      Comment


                        #12
                        Hello aslane,

                        NTEIGHT-14868 has not had an update.

                        When new features or corrections are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal tracking ID, but the description of the feature will let you know if that feature has been implemented.

                        Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                        May I confirm you have tried the suggested steps in post #10 of downloading the Newtonsoft.Json.11.0.2 .NET 4.5 assembly and added a reference to this and this was not affective?

                        Are you asking how to add a reference?
                        https://ninjatrader.com/support/help...indicators.htm
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Chelsea,

                          I was able to get the version you provided to work when placed in Custom. I think part of the problem was we were formally making a ref to the version the program dir which is the wrong version.Thanks.

                          Comment


                            #14
                            The version of NewtonSoft DLL attached here was still incredibly helpful to me 2 years later. I had spent the better part of the last two days trying other approaches to serialize/deserialize strings and objects over sockets and was failing miserably at the deserialization of objects.

                            I tried using System.Web.Script.Serialization .JavaScriptSerializer but couldn't get it to deserialize objects correctly. I tried System.Text.Json .JsonSerializer and couldn't get it to compile, I tried rebuilding the Newtonsoft source against .Net 4.x, I couldn't get that to work because of netstandard issues.

                            Today I placed this DLL into \Bin\Custom, added the references and I was up and running in 3 minutes.


                            Newtonsoft, JSON, serialize, deserialize, netstandard. Serialization, Dserialization.

                            Comment


                              #15
                              None of the existing JSON serialization / deserialized worked for me. 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/dotnet/api/system.web.script.serialization.javascriptserializ er?view=netframework-4.8.1

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,227 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              440 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X