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

How to solve different assemblies after recompile

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

    How to solve different assemblies after recompile

    I have an indicator (MyIndicator), which has an internal class (MyClass).
    My problem is that after a recompile, the assembly changes so this simple check is going to be false:

    if (myObject is MyClass)....

    Why?
    Because after recompile, the assembly changes, so AssemblyQualifiedName is different.

    NinjaTrader.Indicator.MyIndicator+MyClass, 95b2eab7f5ce4ef4a45668b8c386bfdd, Version=7.0.1000.31, Culture=neutral, PublicKeyToken=null

    NinjaTrader.Indicator.MyIndicator+MyClass, 20377f1f822648c8ab1daa5abb59e22b, Version=7.0.1000.31, Culture=neutral, PublicKeyToken=null


    maybe someone can point me to the right direction...

    #2
    Hello Zapzap,

    Thank you for the post.

    Are you specifically seeing this condition become false in your tests or do you have a sample demonstrating the is check not comparing a type correctly? If so could you provide the sample along with any setup instructions needed to see the result you are?

    Generally in the platform we would recommend to use the fully qualified name when comparing types such as:

    if(myObject is NinjaTrader.Indicator.MyIndicator.MyClass)



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

    Comment


      #3
      The two outputs were printed by:

      Print(myObject.GetType().AssemblyQualifiedName);
      Print(typeof(MyClass).AssemblyQualifiedName);

      the problem is smaller with comparsion. The worst part is that it is unable to cast it.

      Comment


        #4
        Hello Zapzap,

        Do you have a specific test you can provide where your comparison is failing along with any setup instructions? Unfortunately I have not had any other specific reports of comparisons like this failing, without a specific example I am unsure of a resolution for your question. If you can provide a sample I could look further into a solution.

        As noted previously I could suggest to use the fully qualified name rather than the AssemblyQualifiedName property.

        You can export the sample you are using that demonstrates the problem using the steps here: http://ninjatrader.com/support/helpG...nt7/export.htm

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

        Comment


          #5
          Okay, this is really a superquick mashup and it trows an internal NT error, so I can't print the assemblies, but it throws the error nonetheless AFTER recompile:
          (can't convert the same class to the same class because they are in different(ly named) assemblies.

          Failed to set property 'MyObject' for indicator 'AssemblyTest': Object of type 'NinjaTrader.Indicator.AssemblyTest+MyClass' cannot be converted to type 'NinjaTrader.Indicator.AssemblyTest+MyClass'.




          PHP Code:
          namespace NinjaTrader.Indicator
          {
              [
          Description("")]
              public class 
          AssemblyTest Indicator
              
          {
                  
          //a simple class
                  
          public class MyClass
                  
          {
                      public 
          string JustAName getset; }
                      public 
          MyClass()
                      {
                          
          JustAName "joe";
                      }
                  }


                  
          //a simple field with a property
                  
          MyClass myObject = new MyClass();
                  [
          XmlIgnore]
                  [
          TypeConverter(typeof(ExpandableObjectConverter))]
                  public 
          MyClass MyObject
                  
          {
                      
          get {return myObject; }
                      
          setmyObject value; }
                  }

                  
          //minimal needed stuff
                  
          protected override void Initialize(){}
                  protected 
          override void OnBarUpdate() {}
              }

          Comment


            #6
            Originally posted by Zapzap View Post
            Okay, this is really a superquick mashup and it trows an internal NT error, so I can't print the assemblies, but it throws the error nonetheless AFTER recompile:
            (can't convert the same class to the same class because they are in different(ly named) assemblies.

            Failed to set property 'MyObject' for indicator 'AssemblyTest': Object of type 'NinjaTrader.Indicator.AssemblyTest+MyClass' cannot be converted to type 'NinjaTrader.Indicator.AssemblyTest+MyClass'.




            PHP Code:
            namespace NinjaTrader.Indicator
            {
                [
            Description("")]
                public class 
            AssemblyTest Indicator
                
            {
                    
            //a simple class
                    
            public class MyClass
                    
            {
                        public 
            string JustAName getset; }
                        public 
            MyClass()
                        {
                            
            JustAName "joe";
                        }
                    }


                    
            //a simple field with a property
                    
            MyClass myObject = new MyClass();
                    [
            XmlIgnore]
                    [
            TypeConverter(typeof(ExpandableObjectConverter))]
                    public 
            MyClass MyObject
                    
            {
                        
            get {return myObject; }
                        
            setmyObject value; }
                    }

                    
            //minimal needed stuff
                    
            protected override void Initialize(){}
                    protected 
            override void OnBarUpdate() {}
                }

            That is an internal framework error message that surprisingly actually has no ill effect and happens only the first time after compilation, but not on any subsequent use. Most of us have learned to live with it.

            Search the forum on the phrase: "cannot be converted to type ", and you will get about 17 threads that discuss the issue in various contexts.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, Today, 08:16 AM
            0 responses
            3 views
            0 likes
            Last Post trilliantrader  
            Started by AttiM, 02-14-2024, 05:20 PM
            9 responses
            174 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by funk10101, Today, 08:14 AM
            0 responses
            1 view
            0 likes
            Last Post funk10101  
            Started by adeelshahzad, Today, 03:54 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by RookieTrader, Today, 07:41 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X