473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3041
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rlrcstr | last post by:
If I have some code behind a form and I want to be able to pass an object to it... any of several user defined classes that I have... and then display the values in the member variables of the...
2
by: Stefan | last post by:
Hello, I was hoping my fellow coders would give me some feedback on the article I wrote which makes use of the System.Reflection namespace and Polymorphism to demonstrate how you can create...
6
by: Robin Haswell | last post by:
Hey guys I was wondering if you could give me a hand with something. If I have two tuples that define a range, eg: (10, 20), (15, 30), I need to determine whether the ranges overlap each other....
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
3
by: bill | last post by:
All, I have the following: ...... unsafe public struct Example { public double we;
2
by: wizofaus | last post by:
Given the following code: public class Test { static unsafe void StringManip(string data) { fixed (char* ps = data) ps = '$'; }
4
by: =?Utf-8?B?QWJoaQ==?= | last post by:
I am using Reflection to invoke methods dynamically. I have got a special requirement where I need to pass a value to method by setting the custom method attribute. As I cannot change the...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.