Boost C++ Libraries: Ticket #5299: Serialization throws an exception for loading binary archive on windows https://svn.boost.org/trac10/ticket/5299 <p> Serialization throws an exception for loading binary archive on windows. THere is no error when using text or xml archive. No error on Ubuntu when using binary, text or xml archive. </p> <p> I have tested the cpp file on both Window XP-x86 and Window 7-x64. The errors are the same. </p> <p> A minimal and complete example is the following: (in s11n_bug.cpp): </p> <pre class="wiki">#include &lt;fstream&gt; #include &lt;boost/archive/binary_iarchive.hpp&gt; #include &lt;boost/archive/binary_oarchive.hpp&gt; #include &lt;boost/serialization/vector.hpp&gt; #include &lt;boost/serialization/shared_ptr.hpp&gt; #include &lt;boost/serialization/nvp.hpp&gt; typedef std::vector&lt;int&gt; B; class A; typedef boost::shared_ptr&lt;A&gt; a_ptr; typedef boost::shared_ptr&lt;B&gt; b_ptr; class A{ public: A(){} A(b_ptr b) : b_(b){} virtual ~A(){} b_ptr b_; friend class boost::serialization::access; template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version){ ar &amp; BOOST_SERIALIZATION_NVP(b_); } }; class DA : public A{ public: DA(){} DA(b_ptr b) : A(b){} template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version){ ar &amp; boost::serialization::make_nvp("base", boost::serialization::base_object&lt;A&gt;(*this)); } }; typedef std::vector&lt;a_ptr&gt; VA; typedef boost::shared_ptr&lt;VA&gt; va_ptr; typedef std::vector&lt;va_ptr&gt; VVA; typedef boost::shared_ptr&lt;VVA&gt; vva_ptr; template &lt;typename Archive&gt; void register_types(Archive&amp; ar){ ar.template register_type&lt;DA&gt;(); } b_ptr make_b(){ return b_ptr(new B); } a_ptr make_a(){ return a_ptr(new DA(make_b())); } va_ptr make_va(){ VA va; va.push_back(make_a()); va.push_back(make_a()); return va_ptr(new VA(va)); } vva_ptr make_vva(){ VVA vva; vva.push_back(make_va()); vva.push_back(make_va()); return vva_ptr(new VVA(vva)); } int main(){ std::string filename = "tmp"; std::vector&lt;vva_ptr&gt; thing; thing.push_back(make_vva()); thing.push_back(make_vva()); { std::ofstream ofs(filename.c_str()); boost::archive::binary_oarchive oa(ofs); register_types(oa); oa &lt;&lt; BOOST_SERIALIZATION_NVP(thing); } { std::ifstream ifs(filename.c_str()); boost::archive::binary_iarchive ia(ifs); register_types(ia); ia &gt;&gt; BOOST_SERIALIZATION_NVP(thing); } return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5299 Trac 1.4.3 Wang Peng <wangp.thu@…> Sun, 13 Mar 2011 14:31:39 GMT attachment set https://svn.boost.org/trac10/ticket/5299 https://svn.boost.org/trac10/ticket/5299 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">s11n_bug.cpp</span> </li> </ul> <p> minimal example </p> Ticket polifa@… Thu, 20 Jun 2013 11:38:04 GMT <link>https://svn.boost.org/trac10/ticket/5299#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5299#comment:1</guid> <description> <p> Is there any news on this? I'm getting the same error using boost-1.54 :O </p> <p> Thanks, Fabio </p> </description> <category>Ticket</category> </item> <item> <author>polifa@…</author> <pubDate>Thu, 20 Jun 2013 11:45:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5299#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5299#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5299#comment:1" title="Comment 1">polifa@…</a>: </p> <blockquote class="citation"> <p> Is there any news on this? I'm getting the same error using boost-1.54 :O </p> <p> Thanks, Fabio </p> </blockquote> <p> I've just figure out the problem. Streams have to be opened with the std::fstream::binary flag. </p> </description> <category>Ticket</category> </item> </channel> </rss>