A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/SonarSource/sonar-dotnet/issues/6912 below:

Unused fields in class with StructLayout · Issue #6912 · SonarSource/sonar-dotnet · GitHub

Description

When class has StructLayout, we need all its props for memory allocation.

Repro steps

For example

public class Foo {

public void Bar(){

  var netResource = new NetResource
  {
                Scope = ResourceScope.GlobalNetwork,
                ResourceType = ResourceType.Disk,
                DisplayType = ResourceDisplaytype.Share,
                RemoteName = "foo"
  };

  _ = WNetAddConnection2(netResource, "pass", "user", 0);

}

        [DllImport("mpr.dll")]
        private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);

        [StructLayout(LayoutKind.Sequential)]
        private struct NetResource
        {
            public ResourceScope Scope;
            public ResourceType ResourceType;
            public ResourceDisplaytype DisplayType;
            public int Usage;
            public string LocalName;
            public string RemoteName;
            public string Comment;
            public string Provider;
        }
}
Expected behavior

no issue

Actual behavior

S1144 on not used props of NetResource struct

Related information

SonarAnalyzer.CSharp 8.54.0.64047


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4