Is there a command line tool that tells me whether a given .Net assembly makes use of COM interop services?
Example that does not make use of COM interop:
internal class ServerClass { }
Example that does:
[ComImport]
[Guid("114383E9-1969-47D2-9AA9-91388C961A19")]
internal class ServerClass { }
CodePudding user response:
I suspect the answer is no.
But you could build one. Start with the output of a decompiler and look for use of types and methods unique to COM interop (eg. Type.GetTypeFromProgID
).
CodePudding user response:
It seems that class and interfaces imported from COM - and that is all that can be COM imported - can be grepped with a simple regular expression (or what findstr
considers a regular expression - note the escaped space, which would otherwise be taken for an "OR" - i.e. a |
in most regex languages):
> ildasm /text NetClient.exe | findstr "\.class.*\ import "
.class interface private abstract auto ansi import NetClient.IServer
.class interface private abstract auto ansi import NetClient.Server
.class private auto ansi import beforefieldinit NetClient.ServerClass
I've tested this with a bunch of dlls already and there was no false positive - I only hope there were no false negatives either...
Also - thanks Simon in the comments - CreateInstance() can be used to load dlls dynamically at runtime, so it should be checked as well (using grep
this time instead of findstr
, due to the latter's unusual and limited regexp syntax):
> ildasm /text file.dll \
| grep -E 'call.*System.Activator|Reflection.Assembly)::CreateInstance'
N.B. ildasm
should come installed with Visual Studio, and is easiest to call when using the Visual Studio Developer Command Prompt.