Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

.net - How do you loop through currently loaded assemblies?

I've got a "diagnostics" page in my ASP.NET application which does things like verify the database connection(s), display the current appSettings and ConnectionStrings, etc. A section of this page displays the Assembly versions of important types used throughout, but I could not figure out how to effectively show the versions of ALL of the loaded assemblies.

What is the most effective way to figure out all currently referenced and/or loaded Assemblies in a .NET application?

Note: I'm not interested in file-based methods, like iterating through *.dll in a particular directory. I am interested in what the application is actually using right now.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Getting loaded assemblies for the current AppDomain:

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

Getting the assemblies referenced by another assembly:

var referencedAssemblies = someAssembly.GetReferencedAssemblies();

Note that if assembly A references assembly B and assembly A is loaded, that does not imply that assembly B is also loaded. Assembly B will only be loaded if and when it is needed. For that reason, GetReferencedAssemblies() returns AssemblyName instances rather than Assembly instances.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...