CA1420:屬性、類型或屬性需要執行時間封送處理
值 | |
---|---|
規則識別碼 | CA1420 |
類別 | 互通性 |
修正是中斷或非中斷 | 中斷 |
原因
使用需要執行時間封送處理的程式碼功能,並明確停用執行時間封送處理。
規則描述
停用執行時間封送處理時,使用需要執行時間封送處理的功能會導致執行時間例外狀況。
如何修正違規
啟用執行時間封送處理,或移除需要執行時間封送處理的程式碼。
隱藏警告的時機
請勿隱藏此規則的警告。
範例
下列程式碼片段顯示 CA1420 違規:
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
[assembly: DisableRuntimeMarshalling]
class C
{
// Violates rule CA1420.
[DllImport("NativeLibrary", SetLastError = true)]
public static extern void MyMethod ();
}
Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices
<Assembly: DisableRuntimeMarshalling>
Class C
' Violates rule CA1420.
<DllImport("NativeLibrary", SetLastError:=True)>
Public Shared Sub MyMethod()
'...
End Sub
End Class
若要修正違規,請移除 DisableRuntimeMarshallingAttribute 元件上的 。