code-analysis

C# Code Analysis CA2000

非 Y 不嫁゛ 提交于 2019-12-12 11:05:51
问题 I have a function which I thought I had fixed the CA2000 warning in Code Analysis for, but it just won't go away. The warning is on SqlCommand. Here's the function: protected internal void LogUserSession(int? managerID) { using (var sqlCommand = new SqlCommand()) { sqlCommand.SetCommand("usp_UserActivity_Create"); SqlParameter prmSessionID = new SqlParameter(); prmSessionID.ParameterName = "@sessionID"; prmSessionID.Direction = ParameterDirection.Input; prmSessionID.SqlDbType = SqlDbType

Why does Code Analysis not warn about NotImplementedException?

99封情书 提交于 2019-12-12 10:45:08
问题 I'm pretty sure that previous versions of Visual Studio Code Analysis warned about the use of NotImplementedException, i.e. any member that contained this throw new NotImplementedException(); would give a CA warning. This doesn't seem to be the case with Visual Studio 2008. Was that particular rule removed, or am I just imagining that it ever existed? 回答1: You are probably thinking about this FxCop warning that you get when throwing NotImplementedException from special methods such as a

CA2213 warning when using ?. (null-conditional Operator) to call Dispose

时间秒杀一切 提交于 2019-12-12 09:34:24
问题 I'm implementing IDisposable , and in my Dispose() method when calling Dispose() on other managed resources I'm using the ?. operator like so: public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if(disposing) { _ChangeLock?.Dispose(); } } I'm still getting the following code analysis error: CA2213: 'MyClass' contains field 'MyClass._ChangeLock' that is of IDisposable type: 'ReaderWriterLockSlim'. Change the Dispose method on

Why do I get Code Analysis CA1062 on an out parameter in this code?

萝らか妹 提交于 2019-12-12 07:54:46
问题 I have a very simple code (simplified from the original code - so I know it's not a very clever code) that when I compile in Visual Studio 2010 with Code Analysis gives me warning CA1062: Validate arguments of public methods. public class Foo { protected static void Bar(out int[] x) { x = new int[1]; for (int i = 0; i != 1; ++i) x[i] = 1; } } The warning I get: CA1062 : Microsoft.Design : In externally visible method 'Foo.Bar(out int[])', validate local variable '(*x)', which was reassigned

Disable warning message of pylint

我与影子孤独终老i 提交于 2019-12-12 01:10:09
问题 Checking code with pylint shows so many messages about variable names as follows: Invalid name "getCurrentChannel" for type method (should match [a-z_][a-z0-9_]{2,30}$) How can I disable these messages ? 回答1: pylint --disable=C0103 filename Running this command will not show messages for "Invalid variable name". 来源: https://stackoverflow.com/questions/21778497/disable-warning-message-of-pylint

How do I validate an enum parameter on a public method?

让人想犯罪 __ 提交于 2019-12-11 17:26:20
问题 I have this extension method for an Enum: public static List<Enum> Values(this Enum theEnum) { return Enum.GetValues(theEnum.GetType()).Cast<Enum>().ToList(); } I'm getting a code analysis violation: CA1062 Validate arguments of public methods In externally visible method 'EnumExtensions.Values(this Enum)', validate parameter 'theEnum' before using it. Why is that happening? How can I validate the parameter? I can't check for null because an enum is a non-nullable value type. Is there some

TFS Build ignores configured Code Analysis ruleset

本秂侑毒 提交于 2019-12-11 13:35:05
问题 I have a solution that is using an hybrid .csproj and project.json combination (for nuget management purposes). So basically the "project.json" file is working as a "packages.config" file with a floating version capability. This solution is using a custom RuleSet that is being distributed via Package, and is imported automatically. On the dev machine, works without a problem. At the build machine (that is, inside the machine itself, working as an user) the solution also compiles without a

How to address the “Do not override the Object.finalize() method” issue

余生颓废 提交于 2019-12-11 12:49:44
问题 Recently I figure out one tool [SonarQube] who helps me to find out the potential threats into code, I have addressed all issues reported by the tool. But it also gives me a potential threats issue for "protected void finalize()" method which is been override by me, tool displaying me a message "Do not override the Object.finalize() method". Can anybody please help me how to address this issue, the overrided method also include some business logic. 回答1: Never. Never! Never put any business

sonar fxcop results not displayed

泪湿孤枕 提交于 2019-12-11 10:41:10
问题 I'm trying to use Sonar on some ASP.Net applications. I have installed Sonar and configured C# environment, and I get this working...except for FXcop (Code Analysis). I followed the official documentation : sonar-runner.bat is ok FXCop path is well configured Sonnar-runner launches FXcop (12.0) correctly FXCop builds the "fxcop-report.xml" in the .sonar directory of the project This file contains some "issues" that I should see in Sonarqube FXCop exit with 1024 code, wich seems ok for sonar

Identifying Connection not closed in java code using PMD

你说的曾经没有我的故事 提交于 2019-12-11 08:48:52
问题 For identifying connection leaks in code, i'm using PMD. Now with PMD, it will identify all collection leaks and show the following error, if it didn't find connection.close(). C:\raghu\Harmony\branch\GlobalSKUPhase1A\source\Java\DataLoadServiceApp\src\dell\harmony\data\JdoServer.java:861: Ensure that resources like this Connection object are closed after use However, with our project code, we also use many customized connection close, i.e) instead of using connection.close(), we call a