Christian
Christian

Reputation: 4375

code analysis warning CA2000 which should not occur

I have a small issue with a CA2000 warning. In my project which is set as startup project, I get this warning, although it should not occur.

Background: I am using Visual Studio 2010 with projects in .NET 3.5. The startup project is a WPF application.

In the class App looks as follows:

public partial class App : System.Windows.Application {

        /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public static void Main() {
            AutoTester.App app = new AutoTester.App();
            app.Run();
        }
    }

The warning says:

Warning 1 CA2000 : Microsoft.Reliability : In method 'App.Main()', call System.IDisposable.Dispose on object 'app' before all references to it are out of scope. C:\Projects\Freelance\svn\AutoTester\Application\Applications\AutoTester\obj\x86\Debug\App.g.cs 47 AutoTester

As one can see, the warning occurs in the App.g.cs which is an auto-generated file. In the project properties I have deactivated code analysis for autogenerated files. "Supress results from auto-generated code". Therefore, this warning should not occur, right?

Now my problem is, that I cannot locally suppress the warning because the code will be overriden. Also, I do not want to make a rule for that globally, because I don't want to deactivate CA2000.

Has anyone encountered a similar problem or any idea what is going wrong here?

Best wishes, Christian

Upvotes: 3

Views: 1045

Answers (1)

Edwin de Koning
Edwin de Koning

Reputation: 14387

"Supress results from auto-generated code" indicates that results from code that is auto-generated is not shown. Visual Studio knows that code is generated by a third-party only if it contains the GeneratedCodeAttribute (see here). Apprarently, the tool that created your code didn't add the attribute.

You can try to make another partial class of App and put the attribute there:

[GeneratedCode("CodeGenerator", "1.0.0.0")]
public partial class App 
{
}

Upvotes: 2

Related Questions