Category: C#

Member [MethodNamd] cannot be accessed with an instance reference; qualify it with a type name instead

Early in a work morning, debugging somebody else’s old code, and without coffee, I get the following error message and got stumped for 2-3 min (Hate to admit with my experience) : Member [MethodNamd] cannot be accessed with an instance reference; qualify it with a type name instead. While this error message can be quite common when updating old code, it...

A required anti-forgery token was not supplied or was invalid

After adding the AntiForgeryToken to prevent Cross Site Request Forgery, I started getting the following message when I was debugging the site “A required anti-forgery token was not supplied or was invalid.” With the following inner exception Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and...

SqlCommand.Parameters.Add() vs SqlCommand.CreateParameter()

When doing some quick research on SQL Parameters with SqlCommand, I noticed two methods which seemed to perform the same task, SqlCommand.Parameters.Add() and SqlCommand.CreateParameter().  After looking into each method on MSDN, I noticed that CreateParameter() will simply create the parameter, while Parameters.Add() will create the parameter and add it to the parameter collection. SqlCommand.Parameters.Add() The following example will create a SQL command object, create...