A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1401 below:

CA1401: P-Invokes should not be visible (code analysis) - .NET

Property Value Rule ID CA1401 Title P/Invokes should not be visible Category Interoperability Fix is breaking or non-breaking Breaking Enabled by default in .NET 9 As suggestion Cause

A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic).

Rule description

Methods that are marked with the DllImportAttribute attribute (or methods that are defined by using the Declare keyword in Visual Basic) use Platform Invocation Services to access unmanaged code. Such methods should not be exposed. By keeping these methods private or internal, you make sure that your library cannot be used to breach security by allowing callers access to unmanaged APIs that they could not call otherwise.

How to fix violations

To fix a violation of this rule, change the access level of the method.

When to suppress warnings

Do not suppress a warning from this rule.

Example

The following example declares a method that violates this rule.

// Violates rule: PInvokesShouldNotBeVisible.
public class NativeMethods
{
    [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
    public static extern bool RemoveDirectory(string name);
}
Imports System

Namespace ca1401

    ' Violates rule: PInvokesShouldNotBeVisible.
    Public Class NativeMethods
        Public Declare Function RemoveDirectory Lib "kernel32" (
        ByVal Name As String) As Boolean
    End Class

End Namespace

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4