-
Notifications
You must be signed in to change notification settings - Fork 237
Closed
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.
Milestone
Description
Description
When class has StructLayout, we need all its props for memory allocation. Even if its embedded in deep class hierarchy. Similar to issue #6912, but fix is not working in edge cases.
Repro steps
For example:
partial class WindowsCredentialService
{
class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
internal struct Credential
{
public int Flags;
public int Type;
[MarshalAs(UnmanagedType.LPWStr)]
public string TargetName;
[MarshalAs(UnmanagedType.LPWStr)]
public string Comment;
public long LastWritten;
public int CredentialBlobSize;
public IntPtr CredentialBlob;
public int Persist;
public int AttributeCount;
public IntPtr Attributes;
[MarshalAs(UnmanagedType.LPWStr)]
public string TargetAlias;
[MarshalAs(UnmanagedType.LPWStr)]
public string UserName;
}Expected behavior
No issue
Actual behavior
S1144 on not used props of Credential struct
Known workarounds
Move struct in class hierarchy:
partial class WindowsCredentialService
{
[StructLayout(LayoutKind.Sequential)]
internal struct Credential
{
public int Flags;
public int Type;
[MarshalAs(UnmanagedType.LPWStr)]
public string TargetName;
[MarshalAs(UnmanagedType.LPWStr)]
public string Comment;
public long LastWritten;
public int CredentialBlobSize;
public IntPtr CredentialBlob;
public int Persist;
public int AttributeCount;
public IntPtr Attributes;
[MarshalAs(UnmanagedType.LPWStr)]
public string TargetAlias;
[MarshalAs(UnmanagedType.LPWStr)]
public string UserName;
}
class NativeMethods
{Related information
- SonarLint for VisualStudio version 8.0.0.92083
- Visual Studio 2022 version 17.9.6
- dotnet version 8
Metadata
Metadata
Assignees
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.