Customizing the Microsoft .NET Framework Common Language Runtime
|
Handling Failures from CorBindToRuntimeEx
Recall that only one copy of the CLR can be loaded in a process at a time. So calling CorBindToRuntimeEx multiple times has no effect. If you do so, S_FALSE is returned on all but the first call. Successful calls to the API return S_OK, as you'd expect. If you pass in a version that is not present on the machine, CLR_E_SHIM_RUNTIMELOAD (defined in CorError.h in the .NET Framework software development kit) is returned. In addition, the dialog box shown in Figure 3-7 is displayed instructing the user to install the desired version of the CLR. Figure 3-7. Incorrect version dialog box
Clearly, scenarios exist, especially in server applications, in which a host would not want to display UI when the requested version of the CLR is not present. You can prevent this dialog box from appearing by calling the SetErrorMode Win32 API before calling CorBindToRuntimeEx. SetErrorMode takes a single parameter that controls whether dialog boxes are displayed for certain types of errors. Be sure to pass SEM_FAILCRITICALERRORS: SetErrorMode(SEM_FAILCRITICALERRORS);
|
|