RE: Reflection across all assemblies
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Mon, 25 Jun 2007 06:26:27 GMT
Hi Tim,
From your description, you're looking for an approach to loop through allthe assembies used in an .NET framework based application(both web and
winform), correct?
As for the AppDomain.GetAssemblies() method you mentioned, it will only
return those assemblies that has been loaded into the AppDomain's execution
context. However, if you call it at the very begining(intialize stage) of
application, since many referenced assemblies may haven't been loaded yet,
you'll miss them through this approach.
I think a reasonable approach should work as below:
** you first get the reference of the executing assembly
** use "Assembly.GetReferencedAssemblies" method to get a list of all the
referenced assemblies of the current executing assembly(for most
application, the root main exe assembly should statically referenced most
required assemblies at compile time).
http://msdn2.microsoft.com/en-us/library/system.reflection.assembly.getrefer
encedassemblies.aspx
** After get a list of assemblies(Actually the AssemblyName list), you can
choose to load them and inspect into it or not. If you only want to reflect
types in it, I suggest you use the "Assembly.ReflectionOnlyLoad" method to
load the assembly into "Reflection ONly context". This is a new feature for
you to inspect type/assemblies in a lightweight context(do not need all the
expensive context info when you actually executing code of the target
assemblies)
#How to: Load Assemblies into the Reflection-Only Context
http://msdn2.microsoft.com/en-us/library/ms172331.aspx
** You can also recursively find the referenced dependency assemblies from
the first List get from the intial executing assembly
Through this approach, you can at least get all those dependency assemblies
you explicitly referenced at design-time/compile time. The only problem is
that if you'll load some assemblies dynamically in code, they won't appear
in the assemblies' static reference list.
In addition, for ASP.NET 2.0 application, you may encounter further problem
since ASP.NET 2.0 application use dynamic compilation and by default page
types may be compiled into multiple temporary assemblies, it is difficult
to locate them from a single central root assembly. However, ASP.NET 2.0
also provide you approach to manually precompile the entire web
application(through "publish website" or "web deployment project"). Thus,
you can still make most page stuff be compiled into some central assemblies
and you can call reflection against those precompiled assemblies.
Just some of my understanding and suggestion. If you have any further
questions or anything unclear, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Prev by Date: Acropolis
- Next by Date: Re: Parsing Text using RegExp
- Previous by thread: Acropolis
- Next by thread: RE: Reflection across all assemblies
- Index(es):
Relevant Pages
|