Resources.LoadAll Generates Cast exception Error

I have a directory under Assets/Resources named “Textures”. It contains two imported image files (.jpg, .png). If I view each of these files in the inspector they appear to be textures. I use them as textures on materials, so I’m pretty sure they are indeed textures.

Using the code snippet directly from the documentation:

Texture2D textures = (Texture2D) Resources.LoadAll(“Textures”)

Returns the following error:

“InvalidCastException: Cannot cast from source type to destination type.”

I have tried changing things about that line of code, such as switching “Texture2D” to “Texture”; adding “as Texture” to the end of the statement; removing the “(Texture2D)” token. The best I can achieve is to get rid of the error by removing the “(Texture2D)” token AND adding “as Texture2D” to the end of the statement, then I no longer generate the error, but my object is null.

HELP!

You can use this, which solves the casting problem for you:

Texture2D[] textures = Resources.LoadAll<Texture2D>("Textures");

try Resources.LoadAll(“Textures”);