CA1009: What should me event look like? RRS feed

  • Question

  • I currently have an event declared as follows:

    Public Event TextChanged(sender As Player, e As TextChangedEventArgs)

    When I do a code analysis, I get the following:

    CA1009 Declare event handlers correctly

    Declare the second parameter of 'Player.TextChangedEventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.

    Does my code not already do that? Am I declaring the event incorrectly? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Saturday, October 4, 2014 10:03 PM


All replies

  • You have done your own class that is called TextChangedEventArgs. What I assume this error is telling you is that TextChangeEventArgs should inherit from the built-in EventArgs class.

    I'm not using VB.Net but I guess the class needs to be declared as follows:

    Public Class TextChangedEventArgs Inherits EventArgs
        'your own properties/methods here
    End Class

    • Proposed as answer by Oliver Ulm Sunday, October 5, 2014 6:57 PM
    • Unproposed as answer by Nathan Sokalski Sunday, October 5, 2014 7:53 PM
    Sunday, October 5, 2014 6:57 PM
  • TextChangedEventArgs is not one of my classes, it is Windows.UI.Xaml.Controls.TextChangedEventArgs that is used in the TextChanged event of other controls such as a TextBox. Also, where does the name TextChangedEventHandler come from? What I am doing is having my UserControl raise the TextChanged event (the one that I declare) when the TextChanged event of a TextBox in the UserControl is raised. It does this fine, I am just trying to figure out what the Code Analysis is complaining about.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Sunday, October 5, 2014 8:01 PM
  • Looking at the inheritance path here: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.textchangedeventargs.aspx

    that event is inheriting from RoutedEventArgs which directly inherits from object. Meanwhile the code analysis seems to check wether you are inheriting from System.EventArgs. What code analysis tool are you using?

    I'd say that in this case the analysis tool is in error (as you're using an appropriate class for the framework you're using).

    Sunday, October 5, 2014 9:08 PM
  • I think you're probably correct in that it just doesn't like the fact that it doesn't inherit from EventArgs, since my code does (and was even when I posted this). The code analysis tool that I am using is the one built into Visual Studio 2013, with the rule set Microsoft All Rules (most of the results I just ignore, but there is occasionally something that is useful). Thank you for your help.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, October 6, 2014 12:31 AM