using UnderlyingSystemType with list of Types from Assembly RRS feed

  • Question

  • I am attempting to use the following code to find occurrences of the derived field within the code.

    The big difference is that for the first 2 tests, I am directly setting the classes

    We using the get assembly and then list of types it never matches, what is the difference 

    As a last minute check I added b2== b check as I know all the classes involved and this again failed to match.

    The input value to the method is of type Record

    What s the difference and why won't it match

      public static IEnumerable<Type> GetDerivedTypes(this Type type)
                Type underlyingSystemType = type.UnderlyingSystemType;
                List<Assembly> assemblies = new List<Assembly>();
                List<Type> z = new List<Type>();

                // Direct type check

                Type a1 = typeof(Record);
                Type b1 = typeof(CurveRecord);
                bool c1 = a1.IsAssignableFrom(b1); // WORKS


                    Assembly assembly = Assembly.LoadFile(underlyingSystemType.Assembly.Location);
                    Type[] t = assembly.GetTypes();
                    foreach(Type b  in t)
                        bool c = underlyingSystemType.IsAssignableFrom(b);
                        if (c)
                        if(b1 == b)
                            // Does not work


    Saturday, November 25, 2017 12:06 PM

All replies

  • I've created quick test and see the code works well if the class is in the main EXE.

    Can you check to see if the "type" variable be passed in is in the same assembly as "CurveRecord"? Try dump "underlyingSystemType.Assembly.Location" and see if it's the same as what you've expected.

    Monday, November 27, 2017 3:41 AM