-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.BadPractice.AvoidCallingProblematicMethodsRule(2.10)
Sebastien Pouliot edited this page Feb 9, 2011
·
3 revisions
Assembly: Gendarme.Rules.BadPractice
Version: 2.10
This rule warns about methods that calls into potentially dangerous API of the .NET framework. If possible try to avoid the API (there are generally safer ways to do the same) or at least make sure your code can be safely called from others.
- System.GC::Collect()
- System.Threading.Thread::Suspend() and Resume()
- System.Runtime.InteropServices.SafeHandle::DangerousGetHandle()
- System.Reflection.Assembly::LoadFrom(), LoadFile() and LoadWithPartialName()
- System.Type::InvokeMember() when used with BindingFlags.NonPublic
Bad example:
public void Load (string filename)
{
Assembly a = Assembly.LoadFile (filename);
// ...
}
Good example:
public void Load (string filename)
{
AssemblyName aname = AssemblyName.GetAssemblyName (filename);
// ensure it's the assembly you expect (e.g. public key, version...)
Assembly a = Assembly.Load (aname);
// ...
}
- This rule is available since Gendarme 2.0
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!