code-analysis

Lint for C# [closed]

痞子三分冷 提交于 2020-08-20 18:11:17
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Is there a lint-like tool for C#? I've got the compiler to flag warnings-as-errors, and I've got Stylecop, but these only catch the most egregious errors. Are there any other must-have tools (especially for newbie C#ers like me) that point out probably-dumb things

Lint for C# [closed]

陌路散爱 提交于 2020-08-20 18:10:42
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Is there a lint-like tool for C#? I've got the compiler to flag warnings-as-errors, and I've got Stylecop, but these only catch the most egregious errors. Are there any other must-have tools (especially for newbie C#ers like me) that point out probably-dumb things

Is PdfStamper disposing output stream? (iTextSharp)

亡梦爱人 提交于 2020-08-09 02:37:27
问题 I am using iTextSharp to add page numbers to a PDF with C#. While running code analysis the MemoryStream for the output is suspected to be disposed more than once. See this warning generated by Visual Studio. Is this an API problem? Should the second parameter of PdfStamper be marked as out ? Is there a way for me to fix this warning? MemoryStream mem = null; PdfReader reader = null; PdfStamper stamper = null; try { mem = new MemoryStream(); reader = new PdfReader(m_pdf); stamper = new

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

拈花ヽ惹草 提交于 2020-07-23 06:41:43
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

那年仲夏 提交于 2020-07-23 06:40:33
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

﹥>﹥吖頭↗ 提交于 2020-07-23 06:39:30
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

这一生的挚爱 提交于 2020-07-10 07:01:11
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

故事扮演 提交于 2020-07-10 07:00:40
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

C# catch(FileNotFoundException) and CA1031

孤人 提交于 2020-06-27 07:28:34
问题 So this code triggers CA1031 . try { // logic } catch (FileNotFoundException) // exception type { // handle error } While this one does not: try { // logic } catch (FileNotFoundException ex) // exception var { // handle error } Because the exception type is meaningful, I don't need the ex in the first example. But it's not a a general exception type. It's not IOException or Exception . So why does it still trigger the CA1031 ? So is there a difference between catch(FileNotFoundException) and

How to deal with enumeration 0 in C# (CA1008 discussion)

喜欢而已 提交于 2020-06-23 02:36:49
问题 Rule CA1008 specifies that all enumerations should have a 0 value that should be named Unknown (we are not discussing flags here). I understand the reason that you want to prevent that uninitialized values would automatically get a meaning. Suppose I define the following enumeration: enum Gender { Male, Female } class Person { public string Name { get; set; } public Gender Gender { get; set; } } This specifies that each person should either be male or female (let's leave out the gender