473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Get Assembly Type Names Without Loading The Assembly

Neo
Does anyone know how to get a list of the types in an Assembly without
actually loading the Assembly into your app domain?

Oct 24 '05 #1
11 10836
Does anyone know how to get a list of the types in an Assembly without
actually loading the Assembly into your app domain?


Yes, by using a metadata reading library other than Reflection.
Microsoft provides a COM API, and there are some other available (with
C# source code) online.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 24 '05 #2
MUS
Hello Neo !

You can do it with "Type.GetType()" but before diving into the
programming world you need to remember following points;

1) If you are using "Type.GetType(<YOUR_TYPE>)" i.e. no assembly is
specified runtime will only look for the type in the calling assembly
and then in mscorlib.dll.

2) If you have a weak assembly i.e. NOT Strong-Named .. for runtime to
look for your type in any other assembly, you need to make a call such
as, Type.GetType(<Your_Type>, <Your_Assembly>); i.e. for example if
you have a type
"MyTestLib.MyClass" in an assembly "MyTestLib" then you need to make a
call like this Type.GetType("MyTestLib.MyClass, MyTestLib");. Reason is
simple, "part of type identity is the assembly".

3) For Strong-Named assembly you need to specify the information in the
following format: "<Your_Type>, <Assembly_Which_Contains_Your_Type>,
<Assembly_Version>, <Assembly_Culture>, <Public_Key_Token>, <Custom>".
For your convenience, below is an example that loads the
"System.Windows.Forms.Shortcut" type and then prints on the console
all the fields name.

<code>
private String SHORTCUT_TYPE_STRING = "System.Windows.Forms.Shortcut,
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089, Custom=null";
Type type = Type.GetType(this.SHORTCUT_TYPE_STRING);
if(type.IsEnum)
{
FieldInfo[] fields = type.GetFields();
foreach(FieldInfo field in fields)
{
if(field.FieldType.Name=="Shortcut")
{
Console.Writeline(field.Name);
}
}
}
</code>

NOTE: But you need to remember onething that assembly WILL GET LOADED
but it will be transparent to you.

You explicitly WONT need to load the assembly by using any of the 3
static methods of Assembly type i.e. "Assembly.Load()" or
"Assembly.LoadFrom()" or "Assembly.LoadFile()" and then with the loaded
assembly reference get the desired type information as,
<Loaded_Assembly_Reference>.GetType(<Your_Type>) ;

Hope this might be of some help.

Let me know in case of any inconsistancy.

Have a good day.

Regards,

Moiz Uddin Shaikh
Software Engineer
Kalsoft (Pvt) Ltd

Oct 25 '05 #3
Neo
Thank you but all of these methods will load the assembly. I This won't
work for me. A lot of times I am loading multiple versions/builds of
the same assembly which causes a crash these assemblies are never
linked in at build time.

However all I need from them is the type names I don't need to execute
any code.

Oct 25 '05 #4
Neo
What is this COM API called?

Oct 25 '05 #5
Neo
What is this COM API called?

Oct 25 '05 #6
Neo
What is this COM API called?

Oct 25 '05 #7
You may find following utility helpful in solving your problem -
(Finding types without loading Assembly),

http://blogs.ineta.org/devin/archive.../07/19424.aspx

regards,
Khurram Shakir
MVP Visual C#

Neo wrote:
What is this COM API called?


Oct 25 '05 #8
Well, then create a new AppDomain, load the assembly in that appdomain
to get the type information and the unload the AppDomain which will
unload the assembly!

Oct 25 '05 #9
And, if you are using VS2005, you can use ReflectionOnlyLoad to load an
assembly for reflection only.

Oct 25 '05 #10
>What is this COM API called?

It's often just called "the unmanaged metadata API". You can find
documentation for it in the Framework SDK Tool Developers Guide\docs\
directory, and the interfaces (IMetaDataImport and
IAssemblyMetaDataImport) are declared in cor.h.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 25 '05 #11
Neo
Yea I saw that in 2005 I guess I may just wait it is right around the
corner. I tried loading it into another AppDomain , the problem is that
the code that actually does the reflection has to live in an assembly
and you have to load that one first which cause a lot of search path
problems. It looks like MS has it figured out with ReflectionOnlyLoad I
have to wait it out.

Oct 25 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Arnaud Debaene | last post by:
Hello group. I have an app which can load "plugins" assemblies that are described in the registry (each registry entry gives the full path to the plugin ..dll file). The plugins may be anywhere...
3
by: Atul Godbole | last post by:
Suppose an assembly "Main" is using class "A" from another Assembly "Dep" as follows : A a = new A(); a.MethodOne(); At what time is the call to MethodOne linked to the actual MSIL (method...
5
by: Abdul | last post by:
I am working on a .net project and need some help. The project contains different components. Each component is in its privated assembly. For e.g Component1 is a C# library project in VS.net and...
4
by: Mark | last post by:
I wan't to be able to deserialize a class from an assembly that is not in the application domain. To do that I must have the Type from the Assembly. How do you get a Type from an assembly that is...
1
by: Luis Pinho | last post by:
Hi There, I've got a server that is waiting for requests, these request correspond to calls to objects that are specified in assemblies stored in the GAC. To do this, I use reflection to call...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
11
by: Neo | last post by:
Does anyone know how to get a list of the types in an Assembly without actually loading the Assembly into your app domain?
0
by: baron06 | last post by:
Hi all ; I 've a main program that support add-ins.First I 'm getting add-ins' names in the button1_Click method then I'm loading the add-in which is choosen by the user in the...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.