Skip to content

Gendarme.Rules.BadPractice.AvoidCallingProblematicMethodsRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

AvoidCallingProblematicMethodsRule

Assembly: Gendarme.Rules.BadPractice
Version: 2.10

Description

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.

Examples

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);
    // ...
}

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally