Second Stanza

June 16, 2009

“Resource not found for the segment …” Azure Exception

Filed under: Azure Platform — Tags: — dfbaskin @ 12:48 pm

Using table storage within the Azure platform, a simple query was throwing an exception if the table entry was not found.


MyDataContext dataCtx = new MyDataContext( acctInfo );
var q = from entity in dataCtx.EmailAddresses
        where entity.PartitionKey == organizationID && entity.RowKey == address
        select entity;
EmailAddress emailAddr = q.FirstOrDefault();
return emailAddr;

I had assumed that an exception would not be thrown if there were no matching entries. The FirstOrDefault() method should have just returned null, right?

Well, not so. Here is a forum message gives a bit of a clue about how the query is actually processed and whether an exception is thrown or an empty data set is returned.

For right now, you’ll have to wrap the query in an exception block:


MyDataContext dataCtx = new MyDataContext( acctInfo );
var q = from entity in dataCtx.EmailAddresses
        where entity.PartitionKey == organizationID && entity.RowKey == address
        select entity;
EmailAddress emailAddr = null;
try
{
    emailAddr = q.FirstOrDefault();
}
catch( DataServiceQueryException ex )
{
}
return emailAddr;

Advertisement

Blog at WordPress.com.