Documenting Interop Assemblies. How to?

I'd like to print all referenced assemblies from within a simple .Net 4 Console Application.
Please see the attached image and help me to fix what I am doing wrong.
Thanks.

static void printAssemblies() {
            foreach (System.Reflection.AssemblyName an in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies()) {
                //System.Reflection.Assembly asm = System.Reflection.Assembly.Load(an.ToString());
                System.Diagnostics.Debug.WriteLine("*-*" + an.FullName);
            }
        }

Open in new window

Just in case: W8, MSVS 2010, .Net 4.0
InteropWanted.png
LVL 1
midfdeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Hmmm...GetReferencedAssemblies doesn't actually return all of the referenced assemblies, if those assemblies are not used in the code anywhere.
0
midfdeAuthor Commented:
>>...if those assemblies are not used in the code anywhere.
The full cource code is below. If I remove any of "interop" references it does not work. I think it means they (components (?), assemblies(?)) are in use. Maybe it does not print them because they are not assemblies, but rather COM components. The question still stands. How can I get what I want (particularly the path)?
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Access;
using Microsoft.Office.Interop.Access.Dao;

namespace testPia {
    class Program {
        static void Main(string[] args) {
            DBEngine dbEng = new DBEngine();
            Database db = dbEng.OpenDatabase(@"\\igorinspiron\Pacrat\Expert\Copy (2) of EXPERT 14.6~.MDB");
            Console.WriteLine(db.Properties.Count.ToString());
            db.Close();
            db = dbEng.OpenDatabase(@"\\igorinspiron\c$\key\fde.key");
            Console.WriteLine(db.Properties.Count.ToString());
            db.Close();
            printAssemblies();
            Console.Read();
        }
        static void printAssemblies() {
            foreach (System.Reflection.AssemblyName an in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies()) {
                //System.Reflection.Assembly asm = System.Reflection.Assembly.Load(an.ToString());
                System.Diagnostics.Debug.WriteLine("*-*" + an.FullName);
            }
        } 

    }
}

Open in new window

-.bmp
0
Bob LearnedCommented:
I find that Mono.Cecil is a lot better at reading the assembly metadata to get the referenced assemblies.  I am not 100% sure it will fit your needs, but you might want to take a look.

With Mono.Cecil, you can AssemblyFactory.GetAssembly to get an assembly, and enumerate the assembly MainModule.AssemblyReferences.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

midfdeAuthor Commented:
Well, I'll take a look, but for now it looks like "to use a steam hammer to crack nuts" for me. Thanks anyway.
0
Bob LearnedCommented:
I believe the problem is that the assemblies are not included when calling GetReferencedAssemblies , so you need to find a working solution.
0
midfdeAuthor Commented:
I beleive the problem is that GetReferencedAssemblies() lists, yes, assemblies, but Interops are not members of ".NET Framework class libraries or assemblies", but rather they are "COM Components".
0
Bob LearnedCommented:
Interop libraries are .NET wrappers to marshal calls to the COM components, but they are still .NET assemblies.
0
midfdeAuthor Commented:
I am about to give up, and I need to read something about it. Not now though, and that's why my question is here. Please see the image in the context of the above conversation.

Thanks, TheLearnedOne, for discussion. You are right: PIA are all assemblies indeed.
-.png
0
Bob LearnedCommented:
You clearly have multiple things going on there.  The assembly probing algorithm is described here:

How the Runtime Locates Assemblies
http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx

1) Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.

2) Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If a previous request to load the assembly failed, the request is failed immediately without attempting to load the assembly.
Note Note

3) The caching of assembly binding failures is new in the .NET Framework version 2.0.
Checks the global assembly cache. If the assembly is found there, the runtime uses this assembly.

4) Probes for the assembly using the following steps:

    a) If configuration and publisher policy do not affect the original reference and if the bind request was created using the Assembly.LoadFrom method, the runtime checks for location hints.

    b) If a codebase is found in the configuration files, the runtime checks only this location. If this probe fails, the runtime determines that the binding request failed and no other probing occurs.

    c) Probes for the assembly using the heuristics described in the probing section. If the assembly is not found after probing, the runtime requests the Windows Installer to provide the assembly. This acts as an install-on-demand feature.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
midfdeAuthor Commented:
As I said, I need to learn.
Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.