views:

49

answers:

3

I want to get information of assembly (classes in the assembly, methods and properties). The name of assembly will be entered through text box.

For this i did like

Assembly ass = Assembly.Load("System.Web")

but it did't work.

Sombody have solution for this?

A: 

You will need complete assembly qualified name.

Vinay B R
+2  A: 

Assembly.Load(string name) requires the long form of the assemblyname. In your case, that's probably something like
Assembly.Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

You can also use the Assembly.LoadFrom(string name) overload with a filename (like System.Web.dll) or a full path, but this is considered less secure than using the long form of the name, because you could load a wrong version of the assembly without knowing it.

Consider reading this article regarding Best Practices for Assembly Loading for a bit more background on why you need to use the LoadFrom overload carefully.

Next step would be to call GetTypes() on your assembly (ass.GetTypes();), and iterate over the returned array of types to get more information like methods and properties.

StephaneT
But in my case user will enter the neme of Assembly in text box so
munish
I need something like user will enter "System.Text" not the complete information Like version and all that
munish
@mun - System.Text is a namespace name, not an assembly name. And it isn't clear which one the user wants. .NET 1.0, 1.1, 2.0, 4.0, Compact editions, Silverlight editions, Mono editions, etcetera. You'll need to think this through. Take a look at how Reflector does it. Or just use Reflector.
Hans Passant
A: 

Another option than calling Assembly.Load() with a fully qualified assembly name might be to simply get to the assembly information for assemblies that you might have already loaded, either explicitly or because you are already using types defined in them.

Simply start with a type you are already using (lets say Namespace.X) and get to the assembly the type is defined in like this:

Assembly ass = typeof(Namespace.X).Assembly;

Or simply ask an instance of an object about the assembly it has been defined in:

object x = new Namespace.X();
Assembly ass = obj.GetType().Assembly;

There is more than one way to skin a ca... eh... to get to an Assembly reference. ;-)

peSHIr