Fix TargetException when serializing a generic dictionary.