JG Vimalan's Blog

It is all about coding!

{System.InvalidOperationException: No data exists for the row or column.

I got this error when I was trying to read values from an OracleDataReader in my C# application.

Here is the code snippet which caused the issue,

OracleDataReader orReader = command.ExecuteReader();
if (orReader.HasRows)
string email = orReader.GetValue(0).ToString();

The cause of the error is simple, I have not used orReader.Read() method.

All I have done is, just verified whether reader has rows. The correct code is as follows,

OracleDataReader orReader = command.ExecuteReader();
while (orReader.Read())
string email = orReader.GetValue(0).ToString();

June 25, 2011 Posted by | C#.NET, Oracle | Leave a comment

HttpContext.Current.Session is null in http handler

I often see developers complaing about HttpContext.Current.Session is null in httphandler.

All you need to do is, implement System.Web.SessionState.IReadOnlySessionState if http handler requires read only access to session – state values.

or else, implement IRequiresSessionState, if you want read and write access to session state variables.

public class Member: IHttpHandler, IRequiresSessionState

this will solve the issue.

June 18, 2011 Posted by | ASP.NET, C#.NET | Leave a comment

System.Security.Cryptography.CryptographicException: Malformed reference element

I got this error when I tried to verify the SAML 2.0 signature. I was using .NET 3.5 webapplication to consume the SAML 2.0 response and then tried to verify the signature. Inorder to fix this error all you need to do is, set the correct XmlElement while performing the signedXml.LoadXml() method. Here is the code snippet I used for fixing the issue.

XmlDocument samlDoc = new XmlDocument();
samlDoc.PreserveWhitespace = true;

var nSpace = new XmlNamespaceManager(samlDoc.NameTable);
nSpace.AddNamespace(“saml2p”, @”urn:oasis:names:tc:SAML:2.0:protocol”);
nSpace.AddNamespace(“saml2″, @”urn:oasis:names:tc:SAML:2.0:assertion”);
nSpace.AddNamespace(“ds”, SignedXml.XmlDsigNamespaceUrl);

var signNode = samlDoc.SelectSingleNode(“/saml2p:Response/ds:Signature”, nSpace);

var signedXml = new SignedXml(samlDoc.DocumentElement);
signedXml.LoadXml(signNode as XmlElement);

if (signedXml.CheckSignature(pubCert, true))
//read the saml data


June 10, 2011 Posted by | ASP.NET, C#.NET, SAML 2.0 | 1 Comment