We use a prefab that includes a image without a sprite, then we load/assign the sprite during Start().
We have a Resizer on this set to Contain, Align = middle/center, and Use Texture Ratio.

This causes an initial exception until we actually assign/load the image.

Changing this line to check the sprite for null fixed the issue:
else if (useTextureRatio && img != null && img.sprite != null) ratio = img.sprite.bounds.size.x / img.sprite.bounds.size.y;

    Write a Reply...