Wednesday, September 30, 2009

404 Resource Not Found For Segment accessing Azure Table Storage

On Windows Azure Table Storage, when you are searching for items (or entities, as the Azure documation calls them) using LINQ on a table, under some circumstances you may get a 404 - Resource Not Found error. That's because Azure Table Storage is REST-based, and REST is about servers serving "resources" to clients. For example, HTTP is REST-based, and when you ask for a file that doesn't exist on a server, you get a "404 Page Not Found" error.

What is happening is pretty much the same. According to a comment by Andrew Conrad, from Microsoft LINQ To REST project team, if you search a list by its keys, you want a specific resource, and if the resource is not found, the 404 error is generated. This may make sense from a REST point of view, but if I'm accessing a table, if I don't find what I'm looking for, I expect a empty resultset, and not an exception. By Andrew's comment above, the LINQ to REST team is aware of this peculiarity on Azure, and plans on doing something more intuitive in the future.

For now you will have to use a ugly try/catch block around your code:
var element =
(for item in azureContext.MyTable
where item.PartitionKey = '...' and item.RowKey = '...'
select item).FirstOrDefault();
catch (DataServiceQueryException ex)
if(ex.Response.StatusCode == 404)
// element not found

Monday, September 28, 2009

Multiple Check-outs on TFS

Team Foundation Server Source Code Control comes with default options that can cause some problems to developers coming from Visual SourceSafe.
  1. Multiple check-outs of the same file are allowed by default. When you try to check in code that has been modified by another developer, a merge conflicts screen appears for you to select what you want to keep and what you want to discard, from yours modifications and from other's too. That can be quite a pain if the file has been through many modifications.

  2. Receiving the latest version of a file on check-out is *not* a default setting. So, even if you disable multiple check-outs, you may still find yourself at the merge conflicts screen, because you worked on code that doesn't have the most recent modifications made to it.
If you like single check-out and think modifications merging is a bad ideia, you have to change the default TFS SCC options. Open the project on Team Explorer, double click Source Code and, on the Team menu, select Team Project Settings > Source Control. Then, reverse selections:

That way there will be no two developers working on the same code at the same time, and you will always be editing the latest version of any code you check out.

Monday, September 14, 2009

STSADM: Access Denied

You may get an "Access Denied" error running the SharePoint command-line administration tool stsadm.exe on Windows 2008, even if you are loggend in with an administrator account. One possible reason for that is UAC (User Access Control). According to the UAC Guide on TechNet, administrators receives two credentials set when they log on: a "normal use" credential and an "administrative" credential. That's because on Vista and W2008 an application may mark itself as administrative task, and when someone tries to start that application, UAC shows the "Windows needs your permission to continue" dialog box:

When you click "Continue", Windows uses the "administrative portion of your logon credentials" to run the application.

The problem is when this dialog box is not shown. For instance, when you open a command prompt and try to run stsadm.exe. You simply get and "Access Denied" message. That's because the command prompt trying to run stsadm has to be opened with administrative rights:

Since the application trying to run stsadm (the command prompt itself) is running with the "administrative credentials" of your administrator account, the access denied message should go away.

Thursday, September 10, 2009

Could not load file or assembly CrystalDecisions.CrystalReports.Engine

If your ASP.NET application does reporting with the Crystal Reports version that comes with Visual Studio 2008 - Crystal Reports 2008 Basic - when you deploy that application to a fresh IIS installation, you will get the message "Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0" etc etc etc. That's because the site needs the Crystal Reports runtime. There's a MSI installation package on machines with VS2008 installed, at C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5. Install the correct MSI (there's one for 32- and another for 64-bit machines), and the application should run ok.