It seems like you are not setting up your dynamically created materials correctly. When you change the underlying shader, you are creating a new material instance that does not have the same properties. The properties cannot be copied because it is not the same underlying shader. You need to setup all the material properties again if you change the underlying shader.