I'm trying to write a custom CLR host for .NET 2.0 in order to revert
to the previous model of unloading the AppDomain when an unhandled
exception occurs, rather than bubbling it up and terminating the
process, which is the new standard behavior. As I understand it, I
need to get a ICLRPolicyManager instance, from which I can easily alter
the unhandled exception handling. However, my attempts to retrieve an
ICLRPolicyManager (or indeed _any_ manager) from
ICLRControl::GetCLRManager result in an HRESULT error code of
0x80131022. In CorError.h I find that 0x801310yy range is reserved for
'Execution Engine' errors, but I can't find more specific information
than that. Does anyone have any ideas? Here's a sample illustrating
the problem:
#include <mscoree.h>
#include <CorError.h>
#include <iostream>
#include <cassert>
#import <mscorlib.tlb> raw_interfaces_only
high_property_prefixes("_get","_put","_putref")
int main() {
ICLRRuntimeHost *host = 0;
if (FAILED(CorBindToRuntimeEx(L"v2.0.50727", L"svr",
STARTUP_SERVER_GC | STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN,
CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*) &host))) {
std::cerr << "Failed to initialize CLR" << std::endl;
return -1;
}
ICLRControl *clrControl = 0;
if (FAILED(host->GetCLRControl(&clrControl))) {
std::cerr << "Failed to get CLR control" << std::endl;
return -1;
}
ICLRPolicyManager *clrPolicyManager = 0;
if (FAILED(clrControl->GetCLRManager(IID_ICLRPolicyManager,
(void**) &clrPolicyManager))) {
std::cerr << "Failed to get CLR policy manager" << std::endl;
return -1;
}
host->Start();
host->Stop();
host->Release();
}
For me, this always ends with 'Failed to get CLR policy manager,' with
the HRESULT failure code previously mentioned. From all the examples
I've seen and documentation I've read, this should work. Maybe I'm
missing something obvious; any help would be greatly appreciated.
Thanks,
noah adler
noah.adler@gmail.com - 20 Jun 2006 21:35 GMT
Well, I found that 0x80131022 maps to HOST_E_INVALIDOPERATION.
However, I still can't find any place in the documentation for
ICLRControl::GetCLRManager that explains why this call should return
such a value. Can anyone shed some light?
Thanks again,
noah
> I'm trying to write a custom CLR host for .NET 2.0 in order to revert
> to the previous model of unloading the AppDomain when an unhandled
[quoted text clipped - 52 lines]
> Thanks,
> noah adler
noah.adler@gmail.com - 27 Jun 2006 19:41 GMT
Well, I found the problem. In hindsight it seems obvious, but just in
case anyone in the future has the problem, I thought I'd document it
here. I was passing the /clr switch to cl.exe, which linked in the
proper libraries and compiled with no problems, but caused these
unexpected errors to occur. Omitting the /clr switch and manually
linking in mscoree.lib solved the problem for me.
Sorry for adding noise to the group, but hopefully it may help someone
else out in the future.
> Well, I found that 0x80131022 maps to HOST_E_INVALIDOPERATION.
> However, I still can't find any place in the documentation for
[quoted text clipped - 60 lines]
> > Thanks,
> > noah adler