Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8426501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:32:52+00:00 2026-06-10T04:32:52+00:00

Update: This occurs when the Code Analysis option Suppress results from generated code (managed

  • 0

Update: This occurs when the Code Analysis option “Suppress results from generated code (managed only)” is turned off, and Rule Set is set to “Microsoft Basic Design Guideline Rules”.

On 2013-04-26, Microsoft confirmed this is a bug, but will not fix it in either this or the next version of Visual Studio.

Link to MS Connect item

We frequently initialize event handlers with an empty delegate to avoid the need for checking nulls. E.g.:

public EventHandler SomeEvent = delegate {};

However, since starting to compile some of our code in Visual Studio 2012 (RTM), I’m noticing a lot of events in derived classes are now triggering CA1601: Do not hide base class methods warnings in Visual Studio 2012’s Code Analysis.

Here’s a sample that will trigger the warning:

using System;
using System.ComponentModel;

[assembly: CLSCompliant( true )]

namespace TestLibrary1
{
    public abstract class Class1
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate {};
    }

    public class Class2 : Class1
    {
        // this will cause a CA1061 warning
        public event EventHandler SelectionCancelled = delegate { };
    }

    public class Class3 : Class1
    {
        // this will not cause a CA1061 warning
        public event EventHandler SelectionCancelled;
    }
}

Note: In VS2012 the warning is triggered when compiled in either .NET 4.5 or .NET 4.0. The same sample does not trigger the warning in VS2010.

Performance reasons aside, are there any legitimate reasons we shouldn’t be initializing events with empty delegates? The default assumption is that it’s probably just a quirk in the analysis in Visual Studio 2012.

Here’s the code analysis result for those that don’t have access to VS2012 yet:

CA1061 Do not hide base class methods Change or remove ‘Class2.Class2()’ because it hides a more specific base class method: ‘Class1.Class1()’. TestLibrary1 Class1.cs 14

Addendum: I found that the option to “Suppress results from generated code” in the code analysis is turned off.

Also, I found that this seems to occur when the event handler in the base type is both:

  • a delegate other than EventHandler or EventHandler -and-
  • events in both the base class and the derived class are initialized using an anonymous method or empty delegate (either inline or in the constructor).

Of possible relevance: We’re running Visual Studio 2012 RTM, which was installed in-place over the release candidate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:32:54+00:00Added an answer on June 10, 2026 at 4:32 am

    The problem is the C# compiler generates a static delegate used to initialize your instance delegate, which is named the same for both Class1 and Class2.

    Class1.CS$<>9__CachedAnonymousMethodDelegate1 exists for use by Class1’s constructor to initialize PropertyCancelled, while Class2.CS$<>9__CachedAnonymousMethodDelegate1_ exists for use by Class2’s constructor to initialize SelectionCancelled.

    It’s unfortunate that the C# compiler doesn’t include some sort of record of the parent class’ auto-generated ‘stuff’ when deciding how to name auto-generated ‘stuff’ for a child class. Crack this open in ILDasm and the issue becomes immediately obvious. Good to know that you found a work around. The warning is completely reasonable to ignore, given that you can’t touch the static delegates from C#, thanks to non-C#-compliant naming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : This is no longer an issue from C# 6, which has introduced
This task occurs from time to time in my projects. I need to handle
UPDATE: This turned out not to be about my database at all, but rather
This problem only occurs in Internet Explorer 8 & 9 I have two dropdowns
Update: This does work, I was being stupid :( i have the following extension
Update: This is, as I was told, no principle Python related problem, but seems
UPDATE: this is a repost of How to make shell scripts robust to source
UPDATE: This question is out of date, but left for informational purposes. Original Question
Update: This question was an epic failure, but here's the working solution. It's based
Update: This question is a duplicate of Are there any programming languages targeting PHP,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.