Does anyone know how to get a list of the types in an Assembly without
actually loading the Assembly into your app domain? 11 10916 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.
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(<Y our_Type>, <Your_Assembly> ); i.e. for example if
you have a type
"MyTestLib.MyCl ass" in an assembly "MyTestLib" then you need to make a
call like this Type.GetType("M yTestLib.MyClas s, 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_Versi on>, <Assembly_Cultu re>, <Public_Key_Tok en>, <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_S TRING = "System.Windows .Forms.Shortcut ,
System.Windows. Forms, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9, Custom=null";
Type type = Type.GetType(th is.SHORTCUT_TYP E_STRING);
if(type.IsEnum)
{
FieldInfo[] fields = type.GetFields( );
foreach(FieldIn fo field in fields)
{
if(field.FieldT ype.Name=="Shor tcut")
{
Console.Writeli ne(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.LoadF rom()" or "Assembly.LoadF ile()" and then with the loaded
assembly reference get the desired type information as,
<Loaded_Assembl y_Reference>.Ge tType(<Your_Typ e>);
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
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.
What is this COM API called?
What is this COM API called?
What is this COM API called?
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!
And, if you are using VS2005, you can use ReflectionOnlyL oad to load an
assembly for reflection only. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 on the disk.
Each plugin defines a class which implements an interface known to the
app. The main app loads the plugin with Assembly.LoadFrom and then
uses Assembly.GetTypes() and Type.FindInterface to find the concrete
types in the plugin that...
|
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
body) of the method? Does this occur when "Main" is build or does it happen
when main is loaded and Jitted? Also is the linking achieved by the full
method name( this is what is seen in the IL generated by ILDASM : e.g : call
|
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
compiles to a dll. Similarly Component2. All components implement an
interface IService which has a Start() method. Now each component is
configured through a config file. The components are created by a
ServiceFactory. Each component has to be run...
|
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 not in the manifest of the
current AppDomain. I have tried different ways but get exceptions from all
of them that say the:
assembly or one of its dependancies could not be found.
There must be missing something.
|
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 the methods.
Now, when I'm trying to optimize the code, I noticed that the
assemblies that are loaded during the reflection call, are never
| |
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 Service dynamically
loads up an assembly that implements an Interface I called IDatabase.
To load the assembly and create an object, I wrote this function:
private IDatabase LoadDatabasePlugin( string assemblyFile, string
|
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?
|
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 combobox1_SelectedIndexChanged method.
private void button1_Click(object sender, EventArgs e)
{
if (adUnLoaded == false)
{
AppDomain.Unload(ad);
|
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 trouble using a library
that creates an instance of a Type that i specified, and it failed the
locate the Type during runtime, if i do not reference it during
compile time.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |