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

NinjaTrader Project in Visual Studio Generates Incompatible C# code

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

    NinjaTrader Project in Visual Studio Generates Incompatible C# code

    Whenever I use the refactor/implement interface tools of Visual Studio 2019, it generates code that is incompatible with the C# version that NinjaTrader uses.

    For example

    Code:
    interface SomeInterface
    {
        int SomeProperty { get; set; }
    
        void SomeFunction();
    
        int SomeOtherFunction(string someParameter);
    }
    
    class SomeImplementation: ISomeInterface
    {}
    Visual Studio will underline ISomeInterface complaining its not implemented by the class. You can then select the option to implement it. Visual Studio will then generate code using the latest C# features instead of ones compatible with C#5.

    I created a brand new project in Visual Studio, specifically set the C# version to 5 per https://docs.microsoft.com/en-us/dot...nguage-version and it generates the code as one expects.

    I tried applying the same things in the article to the NinjaTrader project but it had no effect. Visual Studio will continue to generate incompatible code that I have to fix to get it to compile. My guess is that something about this generated project is not working properly with Visual Studio.

    Is this a known issue?

    #2
    Hello ntbone,

    This is code far outside of what is documented or supported by NinjaTrader.

    This thread will remain open for any community members that would like to provide any suggestions.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      This is not a coding question. Code was provided as an example of something that doesn't generate the proper code, because Visual Studio doesn't seem to be aware that the C# version for the generated NinjaProject provided by NinjaTrader is using C#5. Visual Studio believes the project to be using the latest version of C# so whenever one uses any of the refactoring features of Visual Studio on any of the code in the project, it will potentially generate incompatible code.

      If I create a new .net 4.8 project in Visual Studio, I have to explicitly add something to the project in order for Visual Studio to know that it should use C# 5 instead of the latest. The generated project by NinjaTrader should do the same thing so that when I am using it to code, the proper version of C# is being used.

      Comment


        #4
        Hello ntbone,

        Your inquiry is about the code generated by Visual Studio outside of NinjaTrader.

        I highly recommend you contact Microsoft to further inquire about their software.

        Use the NinjaScript Editor for making NinjaScript specific scripts. This will generate code correctly, especially for indicators. There is nothing in Visual Studio to generate code for NinjaTrader. Nor does microsoft make anything that generates code for NinjaTrader or any other trading platform.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          At this point nothing indicates this is a Microsoft problem. NinjaTrader generates the project that can be opened with Visual Studio. The project I am opening is the one opened by the button in the NinjaTrader editor with the Visual Studio Logo. If NinjaTrader doesn't generate a proper project, it cannot be expected that Visual Studio will behave properly. In this case, since the project doesn't clarify the version of C# it uses, Visual Studio assumes its using the latest version of C#, and thus all the tools contained within it will also attempt to use the latest version of C#.

          Comment


            #6
            Hello ntbone,

            To confirm, this can be reproduced with the NinjaScript Editor, which we directly support?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The editor lacks the functionality to refactor code, among many other functions (including debugging) that the Visual Studio solution, opened when clicking the button from within the editor, contains so its impossible to test.

              Comment


                #8
                Hello ntbone,

                Would you like to submit this as a feature request?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I found and know how to fix the issue. Please submit a feature request to change the generated project per the changes below.

                  In the generated project NinjaTrader.Custom.csproj there is a line "<LangVersion>5</LangVersion>" under

                  Code:
                  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
                    ...
                    <LangVersion>5</LangVersion>    REMOVE THIS LINE
                  </PropertyGroup>
                  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
                    ...
                    <LangVersion>5</LangVersion>    REMOVE THIS LINE
                  </PropertyGroup>
                  then add

                  Code:
                  <PropertyGroup>
                     <LangVersion>5</LangVersion>
                  </PropertyGroup>
                  to the root XML object <Project>. This is what the Microsoft documentation recommends per the link above for specifying a specific version of C# to be used. With this change Visual Studio refactoring tools work properly refactoring code to C# 5 instead of C# latest (I believe it's 8).

                  Just adding the second part without first removing the first part does not seem to impact the Visual Studio refactoring tools.

                  Comment


                    #10
                    +1

                    Please add my vote for this fix.

                    NinjaTrader should provide a properly configured NinjaTrader.Custom.csproj that correctly
                    defines a comprehensive default LangVersion tag (good for all conditions), as suggested
                    by ntbone's research.

                    That is, it appears a simple relocation of the <LangVersion> tag achieves much better
                    downstream integration with the Visual Studio toolset.

                    Good catch, ntbone.

                    Comment


                      #11
                      Hello ntbone,

                      I've submitted the suggested changes as a feature request.

                      Once I have a tracking ID for this request I will post in this thread for future reference.

                      bltdavid, I have added your vote.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello ntbone,

                        This request is being tracked with ID# SFT-5206.

                        Please note, we receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing, so we cannot offer an ETA or promise of fulfillment.

                        When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal feature request 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
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by CortexZenUSA, Today, 12:53 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post CortexZenUSA  
                        Started by CortexZenUSA, Today, 12:46 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post CortexZenUSA  
                        Started by usazencortex, Today, 12:43 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post usazencortex  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        168 responses
                        2,265 views
                        0 likes
                        Last Post sidlercom80  
                        Started by Barry Milan, Yesterday, 10:35 PM
                        3 responses
                        12 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X