By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,983 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,983 IT Pros & Developers. It's quick & easy.

How can I tell (from C# code) if a .DLL is native or a .NET assemb

P: n/a
Hi,

How can I tell (from C# code) whether a .DLL contains native code or is
infact a .NET assembly?

I know that I could use Assembly.LoadFile() and see if it throws a
BadImageFormatException but I really don't want any exceptions in my normal
program flow...

sincerely,
martin
May 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello, martin!

m> How can I tell (from C# code) whether a .DLL contains native code or is
m> infact a .NET assembly?

m> I know that I could use Assembly.LoadFile() and see if it throws a
m> BadImageFormatException but I really don't want any exceptions in my
m> normal program flow...

You will have to analyze file PE format
( http://www.samspublishing.com/articl...p?p=25350&rl=1 )
links in the article are broken, here valid ones
( http://msdn.microsoft.com/msdnmag/issues/02/02/PE/ )

Here is the sample how to do this
( http://geekswithblogs.net/rupreet/ar.../02/58873.aspx )
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 19 '06 #2

P: n/a
One more way to check PE for managed code is "COM Descriptor Directory"
section. If it contains non zero value - file contains managed code

"Vadym Stetsyak" wrote:
Hello, martin!

m> How can I tell (from C# code) whether a .DLL contains native code or is
m> infact a .NET assembly?

m> I know that I could use Assembly.LoadFile() and see if it throws a
m> BadImageFormatException but I really don't want any exceptions in my
m> normal program flow...

You will have to analyze file PE format
( http://www.samspublishing.com/articl...p?p=25350&rl=1 )
links in the article are broken, here valid ones
( http://msdn.microsoft.com/msdnmag/issues/02/02/PE/ )

Here is the sample how to do this
( http://geekswithblogs.net/rupreet/ar.../02/58873.aspx )
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

May 19 '06 #3

P: n/a
> I know that I could use Assembly.LoadFile() and see if it throws a
BadImageFormatException but I really don't want any exceptions in my normal
program flow...


That's why you catch it.

And yet that's the only way to be sure. You can reinvent the wheel, but it
wouldn't be as good/accurate/fast as Microsoft's, and it may need to be
updated in the (unlikely?) event that new DLL formats are created.

Microsoft gave you a tool, use it.

May 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.