“Extension method must be defined in a non-generic static class”

It doesn’t take much time in a Bing search to recognize that this is a common error encountered by .net developers.  Typically though, you have a precise line or method mentioned in the error details when you perform a build.  Within the K2 process designer for Visual Studio, this error is not accompanied by a specific line of code, method or event so troubleshooting can become time-consuming.  In addition, most of the fixes advertised steer you towards adding “static” or “this” to your declarations.  In a code event, you want to do the opposite.

My Case
I encountered this error myself recently after I grabbed and reused some string parsing methods from an old SharePoint even receiver helper class.  In the old class, I had declared my methods as “static” so that I didn’t have to instantiate the class before I used the methods.  Within a K2 server code event, I never modify the event item method declaration, so as I copied these methods into my event code I should have removed the static descriptors… but I forgot 🙂

Identifying the Offending Event
When building the entire process, you don’t get information regarding which event contains the error, but when viewing an event’s .cs file, you only see its own errors. 

  • Right-click your code event and view the code. 
  • CTRL-SHIFT-B  to build the cs file
  • Now you will only see errors that relate to the event you are viewing
    • If you see the “Extension method… “ error then you are in the right place
    • If you don’t see the error, close this event and move onto to the next event in the process


Repair Your Custom Methods
I typically stick to the following:

  • plain class declarations for constant classes
  • private declarations for methods
  • No “this” declarations in the method arguments

Once your individual cs file will build without the error, you can build the entire process and confirm that you have removed all of the offending code.  If not, move open the next server code event and build it to see if it contains a problem.

Happy K2ing! – Joseph