Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out if a .NET assembly contains unmanaged code?

.NET assemblies that contain a mixture of managed and unmanaged code cannot be ILMerged with other assemblies.

How can I verify if a given .NET assembly contains purely managed code, or a mix of managed and unmanaged code?

like image 811
Daniel Fortunov Avatar asked Dec 22 '09 13:12

Daniel Fortunov


2 Answers

As suggested by nobugz, an easier way to see the CLR Flags is using the corflags utility, which is part of the .NET 2.0 SDK.

If no options are specified, the flags for the given image are displayed:

C:\>corflags Foo.dll
Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 9
ILONLY    : 1
32BIT     : 0
Signed    : 1

The "ILONLY" bit indicates whether this is a pure managed assemby, or a mixed assembly.

Note that the comment from user 'nobugz' suggests these flags are not guaranteed to be correct, so this method may not be foolproof.

like image 136
Daniel Fortunov Avatar answered Oct 23 '22 18:10

Daniel Fortunov


Run the PEVerify tool against your assembly.

PEVerify.exe is installed along with Visual Studio, e.g. this one comes with Visual Studio 2012:

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\PEVerify.exe

like image 32
Wim Coenen Avatar answered Oct 23 '22 18:10

Wim Coenen