Skip to content

Gendarme.Rules.Interoperability.Com.AutoLayoutTypesShouldNotBeComVisibleRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

AutoLayoutTypesShouldNotBeComVisibleRule

Assembly: Gendarme.Rules.Interoperability.Com
Version: 2.10

Description

This rule checks for ComVisible value types which have StructLayout attribute set to LayoutKind.Auto because auto layout can change between Mono and .NET or even between releases of the .NET/Mono frameworks

Examples

Bad example:

[assembly: ComVisible (false)]
namespace InteropLibrary {
    [ComVisible (true)]
    [StructLayout (LayoutKind.Auto)]
    public struct Good {
        ushort a;
        ushort b;
    }
}

Good example

[assembly: ComVisible (false)]
namespace InteropLibrary {
    [ComVisible (true)]
    [StructLayout (LayoutKind.Sequential)]
    public struct Good {
        ushort a;
        ushort b;
    }
}

Notes

  • Rule applies only when the containing assembly has ComVisible attribute explicitly set to false and the type has ComVisible attribute explicitly set to true.
Clone this wiki locally