Code analysis for C++/CLI

IJOLB 1 Reputation point
2022-11-04T13:22:01.157+00:00

Hi! I have a question regarding the code analysis of C++/CLI using the Mixed Recommended Rules rule set.

Are the rules for managed code (e.g. CA1001) only applicable to C# code? Or also to managed C++ classes?

Rule CA1001 is detected in Visual Studio when I use the provided example in C# code

public class NoDisposeMethod  
{  
    FileStream _newFile;  
  
    public NoDisposeMethod()  
    {  
        _newFile = new FileStream(@"c:\temp.txt", FileMode.Open);  
    }  
}  

along with the following .editorconfig:

[*.{cs,cpp}]  
  
dotnet_diagnostic.CA1001.severity = warning  

However, with the example being rewritten into managed C++ this is not the case anymore:

public ref class NoDisposeMethod  
{  
    public:  
        System::IO::FileStream^ _newFile;  
  
        NoDisposeMethod()  
        {  
            _newFile = gcnew System::IO::FileStream("c:\\temp.txt", System::IO::FileMode::Open);  
        }  
};  

I'm not sure if this a configuration issue or if the managed rules only apply to C# code.

Thank you very much in advance for your help!

Developer technologies .NET .NET Runtime
Developer technologies C++
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.