Boost C++ Libraries: Ticket #11403: exception_ptr.hpp causes crash when .NET tries to unload a DLL that uses boost https://svn.boost.org/trac10/ticket/11403 <p> Hello, I posted this on the gmane board and Emil Dotchevski said I should open a ticket for this. </p> <p> We are working with Visual Studio 2013 and have a plain c++ lib that uses boost. To test it, we wrote a (non clr) console program and a WPF GUI for further use. This WPF GUI contains a clr dll as a wrapper between the .NET world and the plain c++ libs. At startup, both console and WPF call some function pointers in _initterm in crt0dat.c, especially these two: <br /> dynamic initializer for 'boost::exception_detail::exception_ptr_static_exception_object&lt;boost::exception_detail::bad_alloc_&gt;::e<em>(void) <br /> dynamic initializer for 'boost::exception_detail::exception_ptr_static_exception_object&lt;boost::exception_detail::bad_exception_&gt;::e</em>(void) </p> <p> The console terminates cleanly. But the GUI causes an exception in crtdll.c, _CRT_INIT, line 414: </p> <p> /* call the function, which can eventually change <span class="underline">onexitbegin and </span>onexitend */ <br /> (*function_to_call)(); </p> <p> The debugger says the value of *function_to_call is <br /> *function_to_call _t2m@???<span class="underline">Fep@?1???$get_static_exception_object@Ubad_exception_@exception_detail@boost@@@exception_detail@boost@@YA?AVexception_ptr@1@XZ@YAXXZ@?A0xd1be0c67@@YAXXZ </span></p> <p> and causes an unhandled exception at 0x74c7c42d (<a class="missing wiki">KernelBase</a>.dll), The String binding is invalid. </p> <p> However, if I change (remove the static keyword) line 130 in exception_ptr.hpp from <br /> static exception_ptr ep(shared_ptr&lt;exception_detail::clone_base const&gt;(new exception_detail::clone_impl&lt;Exception&gt;(c))); </p> <p> to </p> <p> exception_ptr ep(shared_ptr&lt;exception_detail::clone_base const&gt;(new exception_detail::clone_impl&lt;Exception&gt;(c))); </p> <p> the GUI exits cleanly. </p> <p> Best regards,<br /> Markus Pieper </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11403 Trac 1.4.3 anonymous Tue, 15 Sep 2015 16:39:08 GMT <link>https://svn.boost.org/trac10/ticket/11403#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11403#comment:1</guid> <description> <p> I have seen the same issue. Another workaround is too prevent <code>exception_ptr.hpp</code> from being included in any managed C++ code. </p> </description> <category>Ticket</category> </item> <item> <author>g.gupta@…</author> <pubDate>Tue, 08 Dec 2015 09:44:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11403#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11403#comment:2</guid> <description> <p> How can we prevent exception_ptr.hpp from being included in any managed C++ code? </p> </description> <category>Ticket</category> </item> <item> <author>g.gupta@…</author> <pubDate>Tue, 08 Dec 2015 09:54:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11403#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11403#comment:3</guid> <description> <p> I am also facing this issue when one third party library having boost static linkage is used on system having boost as shared library &amp; other modules using shared library boost. What is best possible way to resolve this issue ? /usr/lib/libboost_thread.so.1.51.0(_ZN5boost16exception_detail27get_static_exception_objectINS0_10bad_alloc_EEENS_13exception_ptrEv+0x254) i.e boost::exception_ptr boost::exception_detail::get_static_exception_object&lt;boost::exception_detail::bad_alloc_&gt;() /usr/lib/libboost_thread.so.1.51.0 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/libdl.so.2 /lib/ld-linux.so.3 /lib/libdl.so.2 /lib/libdl.so.2(dlopen+0x3c) </p> </description> <category>Ticket</category> </item> </channel> </rss>