# Why does Resources.Load cause a CastException in this case?

I am doing this:

string fontName = "freespin_big";

if (font == null)
{
font = new Font();
AssetDatabase.CreateAsset(font, "Assets/Resources/" + fontName);
}


In Resources, we have freespin_big.png and freespin_big.xml. I am planning to import the png and xml and create a font. So I check if the font object is there, if not create it.

But I get this error if the font does not exist yet:

InvalidCastException: Cannot cast from source type to destination type.

If I try to do this:

Font font = Resources.Load<Font>("blorg");


Where no files are named "blorg", I get null as I expect.

Shouldn't Resources.Load return null if it finds no fonts with the right name?

Font font = Resources.Load("fontname",typeof(Font)) as Font;