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;

      }

}