Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] 1.56.0 - unregistered_class exception while using EXPORTs
From: Robert Ramey (ramey_at_[hidden])
Date: 2014-08-19 20:56:06


Todd Seiler wrote
> I've been pulling my hair out for a couple of days trying to get this to
> work.
>
> When I serialize something from a base pointer, it throws an
> "unregistered_class" exception.

On save or on load? I presume its on load.

> I know the type of object that's being serialized and that class has
> "BOOST_CLASS_EXPORT_KEY" in the header and "BOOST_CLASS_EXPORT_IMPLEMENT"
> in the cpp file with the same name.

For all of the derived classes - right?

Each derived class should serialize it's base with
.... base_object<BaseType *>(this) // i forget the exact syntax.

This includes the void_cast_register so you should never need
to do it.

In the save and load functions I also have:
boost::serialization::void_cast_register(
    static_cast&lt;Derived*&gt;(NULL),
    static_cast&lt;Base*&gt;(NULL));

> should not be necessary if you're serialization all the base objects
> &lt;
> /quote
> The base class is an abstract base class with one pure virtual function
> method. But here are the differences:
> &lt;quote
> &gt;
> 1) I tried using the "ASSUME_ABSTRACT....." macro. That didn't do anything
> for me.

shouldn't make any difference these days

> 2) The abstract base class also has a cpp file with some code in it. I'm
> not sure if that matters or not...

Shouldn't be a problem. Just make sure all the save/load functions
serialize their base objects.

> Here's the thing. I can get the derived class's "save" method to be called
> with this code:
>
> std::ofstream o(case_path_ + "/" + file_name);
> if (o.good())
> {
>
> // MUST HAVE THIS
> boost::serialization::void_cast_register&lt;Derived, Base&gt;(
> static_cast&lt;Derived*&gt;(NULL),
> static_cast&lt;Base*&gt;(NULL));
>
> boost::archive::polymorphic_text_oarchive oa(o);
> boost::archive::polymorphic_oarchive & oa_interface = oa;
> oa_interface << base_ptr;
> }
> Having the void_cast_register() there sort of defeats the purpose though.
> I
> shouldn't need to pre-register them.
> In all the examples, I see the void_cast_register() inside of the "save"
> and "load" methods, which is what I have already.

which examples?

> All my serialization code resides in cpp files.
>
> Also, the serialization code resides in a static lib.
> But the archive creation and the action to serialize is performed in a
> dynamic lib.

REDFLAG - in some environments this is a big no-no as static and
dynamic libraries have different c library implementations. There
is no guarantee that mixing static and dynamic libraries will work.
I recommend using either all one or all the other. Since you're
interested in polymorphic archives - you'll likely want to use
all dynamic.

> I am also using polymorphic archives everywhere.

where? in another application? on another planet?

> I've also forced template instantiation of all serialization code and
> polymorphic archive interface stuff.

But most linkers strip out code which is known to be called. This is
particularly problematic for dlls. The serialization library does
bunch of stuff to make sure such code is not dropped.

> Any clue?

Look at more of the tests and example relating to export.

Robert Ramey

--
View this message in context: http://boost.2283326.n4.nabble.com/Serialization-1-56-0-unregistered-class-exception-while-using-EXPORTs-tp4666610p4666618.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net