We recommend using Visual Studio 2017

Interoperability Warnings


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Interoperability Warnings.

Interoperability warnings support interaction with COM clients.

CA1400: P/Invoke entry points should existA public or protected method is marked by using the System.Runtime.InteropServices.DllImportAttribute attribute. Either the unmanaged library could not be located or the method could not be matched to a function in the library.
CA1401: P/Invokes should not be visibleA public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed.
CA1402: Avoid overloads in COM visible interfacesWhen overloaded methods are exposed to COM clients, only the first method overload retains its name. Subsequent overloads are uniquely renamed by appending to the name an underscore character (_) and an integer that corresponds to the order of declaration of the overload.
CA1403: Auto layout types should not be COM visibleA COM-visible value type is marked by using the System.Runtime.InteropServices.StructLayoutAttribute attribute set to LayoutKind.Auto. The layout of these types can change between versions of the .NET Framework, which will break COM clients that expect a specific layout.
CA1404: Call GetLastError immediately after P/InvokeA call is made to the Marshal.GetLastWin32Error method or the equivalent Win32 GetLastError function, and the immediately previous call is not to a platform invoke method.
CA1405: COM visible type base types should be COM visibleA COM-visible type derives from a type that is not COM-visible.
CA1406: Avoid Int64 arguments for Visual Basic 6 clientsVisual Basic 6 COM clients cannot access 64-bit integers.
CA1407: Avoid static members in COM visible typesCOM does not support static methods.
CA1408: Do not use AutoDual ClassInterfaceTypeTypes that use a dual interface enable clients to bind to a specific interface layout. Any changes in a future version to the layout of the type or any base types will break COM clients that bind to the interface. By default, if the ClassInterfaceAttribute attribute is not specified, a dispatch-only interface is used.
CA1409: Com visible types should be creatableA reference type that is specifically marked as visible to COM contains a public parameterized constructor but does not contain a public default (parameterless) constructor. A type without a public default constructor is not creatable by COM clients.
CA1410: COM registration methods should be matchedA type declares a method that is marked by using the System.Runtime.InteropServices.ComRegisterFunctionAttribute attribute but does not declare a method that is marked by using the System.Runtime.InteropServices.ComUnregisterFunctionAttribute attribute, or vice versa.
CA1411: COM registration methods should not be visibleA method that is marked by using the System.Runtime.InteropServices.ComRegisterFunctionAttribute attribute or the System.Runtime.InteropServices.ComUnregisterFunctionAttribute attribute is externally visible.
CA1412: Mark ComSource Interfaces as IDispatchA type is marked by using the System.Runtime.InteropServices.ComSourceInterfacesAttribute attribute, and at least one of the specified interfaces is not marked by using the System.Runtime.InteropServices.InterfaceTypeAttribute attribute set to ComInterfaceType.InterfaceIsIDispatch.
CA1413: Avoid non-public fields in COM visible value typesNonpublic instance fields of COM-visible value types are visible to COM clients. Review the content of the fields for information that should not be exposed, or that will have unintended design or security effects.
CA1414: Mark boolean P/Invoke arguments with MarshalAsThe Boolean data type has multiple representations in unmanaged code.
CA1415: Declare P/Invokes correctlyThis rule looks for platform invoke method declarations that target Win32 functions that have a pointer to an OVERLAPPED structure parameter and the corresponding managed parameter is not a pointer to a System.Threading.NativeOverlapped structure.