Share via

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++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Your answer

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