midfde
asked on
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.
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);
}
}
Just in case: W8, MSVS 2010, .Net 4.0
InteropWanted.png
Hmmm...GetReferencedAssemb lies doesn't actually return all of the referenced assemblies, if those assemblies are not used in the code anywhere.
ASKER
>>...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)?
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);
}
}
}
}
-.bmp
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.GetAssembl y to get an assembly, and enumerate the assembly MainModule.AssemblyReferen ces.
With Mono.Cecil, you can AssemblyFactory.GetAssembl
ASKER
Well, I'll take a look, but for now it looks like "to use a steam hammer to crack nuts" for me. Thanks anyway.
I believe the problem is that the assemblies are not included when calling GetReferencedAssemblies , so you need to find a working solution.
ASKER
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".
Interop libraries are .NET wrappers to marshal calls to the COM components, but they are still .NET assemblies.
ASKER
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
Thanks, TheLearnedOne, for discussion. You are right: PIA are all assemblies indeed.
-.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As I said, I need to learn.
Thanks again.
Thanks again.