sikender
sikender

Reputation: 5921

how to programatically identify a file as a .NET assembly?

Is there a way to readily find the assemblies?

Upvotes: 3

Views: 578

Answers (3)

Chris
Chris

Reputation: 28064

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.

Upvotes: 2

SLaks
SLaks

Reputation: 887777

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

Upvotes: 1

Jeff Cyr
Jeff Cyr

Reputation: 4864

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

Upvotes: 12

Related Questions