[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

How to detect a managed dll?

Bob Altman

11/13/2008 1:57:00 AM

Hi all,

I need to be able to tell if a DLL is native or managed. The approach most
commonly suggested seems to be to simply try to load the DLL as an assembly
and to catch the appropriate exception if it's not a valid assembly. The
problem with this approach (in my application) is that it winds up
write-locking the DLL. True, I could load the DLL into a different
AppDomain than my main application and then nuke that AppDomain after I've
done my "is it managed" detection, but that's a pain to implement.

Is there some data in the file header that I could look at to determine if
the DLL contains managed code? I have existing code that calls the Windows
MapAndLoad function and digs through the image header for other information
(specifically, the image subsystem to see if it's a GUI application), so if
there is something in the image header that is unique to managed DLLs then I
could easily enough dig that out as well.

TIA - Bob


2 Answers

jetan

11/13/2008 4:12:00 AM

0

Hi Bob ,

The most reliable and easy way to detect this is parsing the PE header. The
CLI specification requires that RVA 15 from the PE header points to the CLI
header. See the links below for more details:
"How to Determine if a file is a .Net assembly (in Delphi and C#)"
http://www.anastasiosyal.com/archive/2007/04...
"How to determine whether a file is a .NET Assembly or not?"
http://geekswithblogs.net/rupreet/archive/2005/11/02/...

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Bob Altman

11/14/2008 1:16:00 AM

0

Thanks Jeffrey, that's just what I was looking for.

Bob