0

I want to develop an application like Visual studio Object Browser, i.e. user will enter something like System.Text namespace or system classes. After button click, we have to find out all classes, functions, properties etc. inside the "System.Text".

I tried the following, but that failed.

        Assembly SampleAssembly;
        SampleAssembly = Assembly.Load("System.Text");

        Type[] Types = SampleAssembly.GetTypes();
        // Display all the types contained in the specified assembly.
        StringBuilder str = new StringBuilder();

        foreach (Type oType in Types)
        {
            str.Append(oType.Name.ToString() + "</br>");
        }
        divAsseblyData.InnerHtml = str.ToString();
staticbeast
  • 2,073
  • 2
  • 22
  • 24
Justinonday
  • 137
  • 3
  • 15
  • yes,got error FileNotFound exception? line 2:SampleAssembly = Assembly.Load("System.Text"); – Justinonday Aug 04 '11 at 10:11
  • 1
    There is no such thing as a 'System.Text' assembly; it is only a namespace inside mscorlib.dll. Rewrite your code to load mscorlib and navigate then to the System.Text namespace. – Edwin de Koning Aug 04 '11 at 10:39
  • ok thank you Edwin sir..thats right!..In mscorlib.dll how can i navigate System.Text or System.Web? – Justinonday Aug 05 '11 at 06:18

1 Answers1

2

'System.Text' is a namespace not an assembly so i assume you want to load the assembly 'System'.

To use Assembly.Load() with a string parameter you need to pass the fully qualified name of the assembly.

To obtain the fully qualified name you can do something like this:

Assembly SampleAssembly;
SampleAssembly = Assembly.Load(typeof(System.Activator).Assembly.FullName);
// get the type of some random object in the assembly (Activator) and then
// call .Assembly.FullName which returns the fully qualified name of the assembly

Or you can press Win + R, type "Assembly" and enter, then right click -> proprieties on the assembly which you need and set manually the proprieties in code in the format:

"mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

SampleAssembly = Assembly.Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • That's an awesome tip for finding the name of an assembly! – Jacob Aug 05 '11 at 01:55
  • ok thank you so much Razan Panda sir.can you share what to do next.!ie in mscorlib.dll how can i navigate System.Text or System.Web? – Justinonday Aug 05 '11 at 06:20
  • @Justin: what do you mean by navigate? what do you need to do? – Răzvan Flavius Panda Aug 05 '11 at 09:23
  • @Razan : navigate means ie. actually i need to get all properties ,function name of a class.if user enter "String.Text.StringBuilder" class then i have to show them all properties and methods of that class.Please help me..! – Justinonday Aug 05 '11 at 10:25
  • @Justin: see the examples in this post http://stackoverflow.com/questions/3196504/in-c-is-there-anyway-to-determine-a-classs-members-at-runtime of how to get class members – Răzvan Flavius Panda Aug 05 '11 at 10:49