![JAR search and dependency download from the Maven repository](/logo.png)
org.sonar.plugins.csharp.S4214.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonarlint-omnisharp-plugin Show documentation
Show all versions of sonarlint-omnisharp-plugin Show documentation
Code Analyzer based on Omnisharp
This rule is deprecated; use {rule:csharpsquid:S4200} instead.
Why is this an issue?
Methods marked with the System.Runtime.InteropServices.DllImportAttribute
attribute use Platform Invocation Services to access
unmanaged code and should not be exposed. Keeping them private or internal makes sure that their access is controlled and properly managed.
This rule raises an issue when a method declared with DllImport
is public or protected.
Noncompliant code example
using System;
using System.Runtime.InteropServices;
namespace MyLibrary
{
public class Foo
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool RemoveDirectory(string name); // Noncompliant
}
}
Compliant solution
using System;
using System.Runtime.InteropServices;
namespace MyLibrary
{
public class Foo
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern bool RemoveDirectory(string name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy