I have a C++ application which uses controls contained in a managed (C#) library.
The controls are activated using Registry-Free COM Interop (SxS activation). If the managed library is missing, the application shuts down immediately with a generic and unhelpful dialog: ("Unable to start program X", "This Application has failed to start... blah...blah") What I would like to do, is catch the error and present the user with my own (hopefully more helpful) message. Better yet, I would like to allow the application to continue loading and just disable the few dialogs that actually use the managed library and its controls (only a tiny fraction of the main application uses this library). Unfortunately, the error from the SxS loader seems to happen before any of my code gets a crack at handling it. Can I catch and handle these errors? If so, how? Thanks!
Asked
Active
Viewed 126 times
0
-
The problem is that the error is generated by the system loader before it even tries to enter your code. Is there a way of marking the libraries as optional in the manifest and testing for them after startup? – Richard Critten Jul 27 '18 at 18:26
-
Exactly. "Is there a way of marking the libraries as optional in the manifest...?" I wish I knew! :) If that's possible, I'd like to know how, but in my reading I haven't seen a way. – kshill Jul 27 '18 at 18:31
-
you can't ship the DLLs you depend on with your product? – Joseph Willcoxson Jul 27 '18 at 21:05
-
1You'd have to activate the manifest yourself instead of leaving it up to the loader to do it for you. http://www.mazecomputer.com/sxs/help/sxsapi2.htm – Hans Passant Jul 27 '18 at 21:23
-
Joseph - If only it were that easy. Our installation/update procedure (if you can call it that) is too chaotic to guarantee that the dll is there and is the right version. – kshill Jul 30 '18 at 14:30
-
Hans - I'll look into that. Thanks. – kshill Jul 30 '18 at 14:31
-
Manually loading the Activation Context was the ticket. Hans - you should post this as an answer. – kshill Aug 02 '18 at 10:05