Encode strings that may receive non-ascii characters to utf-8.

Layer's with special characters in the typename will cause update layers to fail.  This patch encodes the unicode instances of typename to utf-8 when converting to a string.  I've looked around, but can't find a better way to handle this. I will improve this patch if anyone has suggestions.