Boost logo

Boost Users :

From: Terence Wilson (tez_at_[hidden])
Date: 2006-06-15 11:38:09


Dear Robert,

 

I have also been stymied by this bug, for me it is a show stopper because
our application is composed of many DLL's rather than a single executable.
If it would help you, I can provide a small VC8 project which demonstrates
the issue. I'm motivated to help you fix the problem as your library could
potentially be very useful in our work.

 

Could you please explain what you mean by registered twice? As I understand
it, the base and derived classes should be registered, is this what you
refer to or do you mean registered twice, the same class once in each
module?

 

Thanks for your help,

 

Terence

 

 

  _____

From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: Tuesday, June 13, 2006 1:23 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] boost::serialization
unregistered_classexceptionswith DLL.

 

This has been bugging me for a while but I never really found the time to
really track it down. Perhaps you could do a little sleuthing while your
there. I would expect that the problem due to the fact that foobar_base is
"registered" twice - once when the app starts up and a second time when the
derived class DLL is "registered" when the DLL is loaded. So I believe that
the problem would not appear if foobar_base were in the DLL as well.

 

The reason that I've enforce the restriction that serialization code be
instanticiated only once was that when It was permitted multiple times, the
"unregister" code would sometimes remove the wrong instance. So that things
would crash in an unpredictable and obscure way. Its still not clear to me
the best way to handle this. I guess that the eti has to be "registered"
along with a handle to its code module (executable, dll or shared library).
So far I haven't spent any time on investigating this.

 

Thanks for a good example which illustrates the problem in a digestable
manner.

 

Robert Ramey

 

 

"Arjuna Balasingham" <abalasingham_at_[hidden]> wrote in message
news:004a01c68f13$3bae3120$56d8ac41_at_gatan.com...

Re: unregistered_class exceptions are thrown when the derived class are in
an explicitly loaded DLL.

 

Hello,

 

In a nutshell, the problem that I have is that an "unregistered_class"
exception is thrown when the derived class is defined/declared in a DLL that
is explicitly loaded.

The problem as far as I can tell is that the derived class in dll and the
derived class in the framework are being "registered" in two different
instances (m_self->m_map.insert(eti); in "extended_type_info.cpp").

 

Exception is thrown when trying to serialize the foobar_derived_dll. It
looks for "foobar_derived_dll" in the wrong instance of the m_map defined in
the extened_type_info.cpp and then throws an exception.

 

Can anybody please help

 

The Application Structure is more or less as follows.

 

Common Framework Library Contains.

class foobar_base : public foobar_base

{

protected:

      bool m_attr0;

 

public:

      foobar_base() {}

      template<class Archive>

      void serialize(Archive & ar, const unsigned int /* file_version */){

            std::cout << "serialize foobar_base\n";

            ar & BOOST_SERIALIZATION_NVP(m_attr0);

}

}

 

class foobar_derived : public foobar_base

{

protected:

      bool m_attr1;

 

public:

      foobar_derived() {}

      template<class Archive>

      void serialize(Archive & ar, const unsigned int /* file_version */){

            std::cout << "serialize foobar_derived_dll\n";

ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(foobar_base);

            ar & BOOST_SERIALIZATION_NVP(m_attr1);

}

}

BOOST_CLASS_EXPORT_GUID(foobar_derived, "foobar_derived")

 

 

 

Dynamic Link Library Contains (Includes Common Framework Library)

class foobar_derived_dll

{

protected:

      bool m_attr2;

 

public:

      foobar_derived_dll() {}

      template<class Archive>

      void serialize(Archive & ar, const unsigned int /* file_version */){

            std::cout << "serialize foobar_derived_dll\n";

ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(foobar_base);

            ar & BOOST_SERIALIZATION_NVP(m_attr2);

}

}

BOOST_CLASS_EXPORT_GUID(foobar_derived_dll, "foobar_derived_dll")

 

 

 

 

Main Application (includes Common framework library & explictly lods Dynamic
Link Library)

class foo {

public:

      std::list<boost::shared_ptr<foobar_base> > m_foovec;

 

public:

      foo ( ) { };

      ~foo ( ) { };

 

      template<class Archive>

      void serialize(Archive &ar, const unsigned int version)

      {

            ar & BOOST_SERIALIZATION_NVP(m_foovec);

      }

};

 

 

(..Include Framwork..)

int main() {

 

      // load the DLL..

      LoadLibrary(... DLL)"

      

      foo f;

f.m_foovec.push_back( boost::shared_ptr<foobar_base>(new foobar_derived(....

f.m_foovec.push_back( boost::shared_ptr<foobar_base>(new
foobar_derived_dll(....

 

      std::string filename("c:\\tmp.txt");

      try {

            // write to file

            std::ofstream ofs(filename.c_str());

            assert(ofs.good());

            boost::archive::text_oarchive oa(ofs);

 

            oa << BOOST_SERIALIZATION_NVP(f);

            ofs.close();

      } catch (std::exception &e) {

            std::cout << e.what() << std::endl;

      }

}

 

  _____

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



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