When class has StructLayout, we need all its props for memory allocation.
Repro stepsFor 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 behaviorS1144 on not used props of NetResource struct
Related informationSonarAnalyzer.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