Can't set sharedmaterials

So recently I’ve been trying to add some basic optimization to my code by using using a shared material. I’ve got my code working originally with a non shared one by using the line:

tempFace.GetComponent(MeshRenderer).material.SetTexture("_MainTex", Resources.Load(type, Texture2D));

I’ve tried to change this to:

tempFace.GetComponent(MeshRenderer).sharedMaterial.SetTexture("_MainTex", Resources.Load(type, Texture2D));

But all I got was a null reference exception. Can anybody point out as to what I’m doing wrong here?

Is that sharedMaterial created?
sharedMaterial is null?

Check you have implemented smth like this::

MeshRenderer mr = tempFace.GetComponent(MeshRenderer) as MeshRenderer;
mr.sharedMaterial = new Material(Shader.Find("MyShader"));