Detecting a dll type (.NET Assembly or not)

  • Thread starter Thread starter George Straw
  • Start date Start date
G

George Straw

I'm attempting to load an arbitrary DLL in a .NET application.
I want to check to determine if it's indeed a .NET assembly, but
I want to do it without throwing a BadImageFormatException, as in
the following:

internal bool IsReallyAGenuineDotNetAssembly(string fileName){

try {
Assembly.LoadFrom(fileName);
return true;
} catch (BadImageFormatException ex) {}

return false;
}

Is there a way to do what I want to do without having to throw
an exception?

GS
 
is it not OK for you to catch the exception?

If you are allergic to exceptions, the other option is to open the binary
file for reading, and inspect the file to verify that it is infact a managed
DLL. But for that you would have to embed lots of specific PE file format
knowledge into your app,

eg, see
http://www.codeguru.com/cs_misc/CreatingAndUsing.html

if you go this route, you could use a 3rd party PE file parser to help you.
eg, http://www.jbrowse.com/products/asmex/

-Dino
 
Back
Top