Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-06-13 16:22:52


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