Marshal.dump generates binary data, not containing any real strings
(try "puts str" and see). Therefore trying to encode it will blow up -
either with an immediate error, like it did for you, or it will appear
to work and only corrupt the data..

You can get the string data back by using Marshal.load str.

-- Matma Rex