Category: C#

Grouping Objects by using GroupBy using LINQ in C#

Ever need to group by a property and want to use LINQ to do so? Happened to me recently and decided to explore the really simple way to group objects using LINQ using GroupBy. I started off by creating a simple class for a person and created a list Next add the following line This will group your list, people by the...

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...

SqlDataAdapter Will Not Always Return a Result, SSMS Will

The Issue I ran into a strange issue with an ASP.NET site (MVC2 – 4.0 Framework) where when executing a stored proc, SqlDataAdapter.Fill(DataTable) will not return any rows some of the time, but SQL Server Management Studio will almost immediately return results. The full method calling the stored procedure is below : (Auto-generated from LLBL Pro V2.6) This issue occurs...

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...

The image cannot be decoded. The image header might be corrupted

I was recently trying to send to Telerik’s image editing control a jpeg image in a stream format. I was checking for the other types and using the appropriate format providers, but I kept getting an exception when working with JPEGs : The image cannot be decoded. The image header might be corrupted With the following code : So, I...

%d bloggers like this: