How to enable texture reading using TextureImporter in an EditorScript?

The following code worked great until I upgraded to Unity 3.2, and now it gives a "InvalidCastException: Cannot cast from source type to destination type" error on the first line and dies. I tried every typecasting trick I could think of, but none of them worked. Any ideas?

var textureImporter : TextureImporter = AssetImporter.GetAtPath(path);
if (textureImporter.isReadable == false) {
    textureImporter.isReadable = true;
    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
}
texCur = AssetDatabase.LoadMainAssetAtPath(path);

var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;

However, although I don't like dynamic typing, your original code works fine for me, as long as #pragma strict is not used.