Working with dynamic materials/shaders in Unity

So I decided to test a standalone build of a Unity project I am working on and encountered a severe performance issue. I was getting about 15 frames per second, which made no sense at all. At first I thought it was to do with some new objects I had just added or too many normal maps or something.

It turns out that the standalone version did not like something I was doing with dynamically created Materials, and was logging thousands of lines a second to the output_log.txt file. This was the error in the log:

To work around it, I simply had a create a new Material in the editor (left blank/default) of the same type (Reflective/Specular), and stick it in the Resources folder. The code to do the same customization is as follows, and works fine.