472,127 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

.NET Reflection: Determing whether a method is unsafe

I am loading an assembly using reflection.
Then I get all the methods in all types.
I want to check whether a method is "unsafe".
The MethodInfo class does not seem to provide this information.
How can I get the info?

Thanks and Regards
Manish Soni
Nov 16 '05 #1
2 2947
Manish,

Unfortunately, you can not tell this on the method level (think, how
would you determine if there was an unsafe block of code inside the
method?).

The best you can do is check the module that the method on the type is
in. On the module, check to see if it has the UnverifiableCode attribute
attached to it. If it does, then this means that the compiler flag was set
to allow unsafe code (however, this doesn't mean that there necessarily is
unsafe code).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Manish Soni" <ms***@microsoft.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
I am loading an assembly using reflection.
Then I get all the methods in all types.
I want to check whether a method is "unsafe".
The MethodInfo class does not seem to provide this information.
How can I get the info?

Thanks and Regards
Manish Soni

Nov 16 '05 #2
The SDK comes with a tool called PEVerify.exe. See if you can run this
on your assembly before using reflection to load it into your application.

You might want to use the methods in Process class (from
System.Diagnostics namespace) to run PEVerify.exe.

eg., assume your test assembly is called abcd.dll
so, you'd run...

PEVerify.exe abcd.dll /md > results.txt

now, parse through the results.txt to see if it came up with any errors.
If the code is verifiably safe, you'd come up with something like...
================================================== =========
Microsoft (R) .NET Framework PE Verifier Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

All Classes and Methods in abcd.dll Verified.
================================================== =========

Hope this was of some help.
-Azhagan.

"Manish Soni" <ms***@microsoft.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
I am loading an assembly using reflection.
Then I get all the methods in all types.
I want to check whether a method is "unsafe".
The MethodInfo class does not seem to provide this information.
How can I get the info?

Thanks and Regards
Manish Soni

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rlrcstr | last post: by
2 posts views Thread by Stefan | last post: by
6 posts views Thread by Robin Haswell | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.