Partager via


CA1406: Avoid Int64 arguments for Visual Basic 6 clients

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
TypeName AvoidInt64ArgumentsForVB6Clients
CheckId CA1406
Category Microsoft.Interoperability
Breaking Change Breaking

Cause

A type that is specifically marked as visible to Component Object Model (COM) declares a member that takes a System.Int64 argument.

Rule Description

Visual Basic 6 COM clients cannot access 64-bit integers.

By default, the following are visible to COM: assemblies, public types, public instance members in public types, and all members of public value types. However, to reduce false positives, this rule requires the COM visibility of the type to be explicitly stated; the containing assembly must be marked with the System.Runtime.InteropServices.ComVisibleAttribute set to false and the type must be marked with the ComVisibleAttribute set to true.

How to Fix Violations

To fix a violation of this rule for a parameter whose value can always be expressed as a 32-bit integral, change the parameter type to System.Int32. If the value of the parameter might be larger than can be expressed as a 32-bit integral, change the parameter type to System.Decimal. Note that both System.Single and System.Double lose precision at the upper ranges of the Int64 data type. If the member is not meant to be visible to COM, mark it with the ComVisibleAttribute set to false.

When to Suppress Warnings

It is safe to suppress a warning from this rule if it is certain that Visual Basic 6 COM clients will not access the type.

Example

The following example shows a type that violates the rule.

using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
namespace InteroperabilityLibrary
{
   [ComVisible(true)]
   public class SomeClass
   {
      public void LongArgument(long argument) {} 
   }
}
Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(False)>
Namespace InteroperabilityLibrary

   <ComVisibleAttribute(True)> _ 
   Public Class SomeClass

      Public Sub LongArgument(argument As Long)
      End Sub

   End Class

End Namespace

CA1413: Avoid non-public fields in COM visible value types

CA1407: Avoid static members in COM visible types

CA1017: Mark assemblies with ComVisibleAttribute

See Also

Interoperating with Unmanaged Code Long Data Type