tags:

views:

189

answers:

3

Is there a way to readily find the assemblies?

+12  A: 

How to programmatically determine if a file is an assembly

Call the GetAssemblyName method, passing the full file path and name of the file you are testing.

If a BadImageFormatException exception is thrown, the file is not an assembly.

http://msdn.microsoft.com/en-us/library/ms173100.aspx

SelflessCoder
+1  A: 

Call AssemblyName.GetAssemblyName and see whether it throws an exception.

SLaks
+1  A: 

In addition to Jeff's suggestion, there appears to be a method to test if an assembly is managed without throwing an exception documented here: http://www.codeguru.com/forum/showthread.php?t=424454

Actually, if you open a .NET Library / Application in a binary editor, you will see that the ASCI text "BSJB" is shortly followed by the version of the Framework that the DLL / EXE needs.

So, depending on the presence of this search attribute, you can not only identify whether the library / executible is a managed library, but also the version of the Framework it uses.

Chris
DON'T DO STUFF LIKE THIS. It is not guaranteed to work in any way, shape or form in the future.
Stu
If you read further down that same page, there are better ways documented as well. In addition, I find your all caps statement rather annoying. Some hacks such as this one can be used to good benefit in combination with a fail-safe. The number of assemblies being checked by the OP probably doesn't warrant a second thought, but in case it does, it's always good to try to avoid relying on exceptions as a part of normal process flow. If the assembly can be checked faster using a hack first, why not try it?
Chris