Hi, I'm not good with english but I hope to help you.
I have the same problem, I'm working with API JS 3.12 and AGS 10.5, the problem was the same as the first of the list when I set the layer definition directly on a dynamic layer previously charged. So, in my case I solved it by modyfing the init.js, on the next method
original method:
setLayerDefinitions:function(b,c){this.layerDefinitions=b;this._params.layerDefs=a._serializeLayerDefinitions(b);this._updateDynamicLayers();c||this.refresh(!0)}, changed to
new method:
setLayerDefinitions:function(b,c){this.layerDefinitions=b;this._params.layerDefs="{"+a._serializeLayerDefinitions(b)+"}";this._updateDynamicLayers();c||this.refresh(!0)};
Whatever it solved my problem.