Programatically added material is missing shader

I have created a custom shader, and assigned it to a material. If I then programatically assign the material to an object (I use (Material)Resources.Load(…) to get the material) the material is assigned, but it is using the default shader.

Even if I try myMaterial.shader = myShader in the code it does not update the shader. I have tried placing the shader in the Resources folder and adding it to Edit > Project Settings > Graphics > Always included shaders but neither helps.

However If I add the material to an object via the editor the shader is correct.