Reputation: 11
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?
Upvotes: 1
Views: 870
Reputation: 6360
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. ;-)
Upvotes: 1
Reputation: 2714
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.
Upvotes: 4