[Mono-list] Reflection problem

Sanjaya Singharage SanjayaS@jkcs.slt.lk
Fri, 14 Feb 2003 13:27:27 +0600


Hi all,
I am using the following class to discover classes, methods and properties.
But for some classes (or are they interfaces) like
System.Web.UI.WebControls.DataGrid and System.Data.IDbCommand when I call
the method DispClsMethods I get the following error. Can somebody explain?

Unhandled Exception: System.NullReferenceException: A null value was found
where an object instance was required
in <0x0003b> 00 .ClassDets:DispClsMethods (string)
in <0x00041> 00 .ClassDets:Main ()

The code for the class follows.

using System;
using System.Reflection;
using System.Web.UI.WebControls;
using System.Web.UI;

public class ClassDets
{
      public void DispAssemblies()
      {
            //AssemblyName[] an = Assembly.GetReferencedAssemblies();
      }

      public void DispClsMethods(string strType)
      {
            Type t = Type.GetType(strType);
            MethodInfo [] mi = t.GetMethods();

            Console.WriteLine("milepost 3");
            foreach(MethodInfo m in mi)
            {
                  Console.WriteLine(m);
            }
      }

      public void DispClsProps(string strType)
      {
            Type t = Type.GetType(strType);
            PropertyInfo [] pi = t.GetProperties();
            foreach(PropertyInfo p in pi)
            {
                  Console.WriteLine(p);
            }

      }

      public void PrintClsFromAss(string strAssemblyName)
      {
            Assembly a = Assembly.Load(strAssemblyName);
            Type[] types = a.GetTypes();
            foreach(Type t in types)
            {
                  Console.WriteLine(t);
            }
      }

      public static void Main()
      {
            ClassDets cd = new ClassDets();
            //cd.PrintClsFromAss("System.Data.dll");
            cd.DispClsMethods("System.Data.IDbCommand");
            //cd.DispClsMethods("System.Web.UI.WebControls.Table");
            //cd.DispClsProps("System.Reflection.Assembly");
      }

}