none
Sample hosting the .NET 4.0 runtime in C++ RRS feed

  • Question

  • The all-in-one samples have an example of hosting the .NET 4.0 runtime. The problem is that it doesn't show how to use the ICLROnEventManager interface. I have tried:

    ICLROnEventManager *clrOnEventManager = NULL;
    HRESULT hr = pControl->GetCLRManager(IID_ICLROnEventManager, (void**) &clrOnEventManager);
    ThrowOnError(hr, "GetCLRManager failed");
    hr = clrOnEventManager->RegisterActionOnEvent(Event_ClrDisabled, pHost);
    ThrowOnError(hr, "RegisterActionOnEvent Event_ClrDisabled failed");
    hr = clrOnEventManager->RegisterActionOnEvent(Event_DomainUnload, pHost);
    ThrowOnError(hr, "RegisterActionOnEvent Event_DomainUnload failed");
    hr = clrOnEventManager->RegisterActionOnEvent(Event_MDAFired, pHost);
    ThrowOnError(hr, "RegisterActionOnEvent Event_MDAFired failed");
    hr = clrOnEventManager->RegisterActionOnEvent(Event_StackOverflow, pHost);
    ThrowOnError(hr, "RegisterActionOnEvent Event_StackOverflow failed");

    but the only event I get is Event_DomainUnload. Never Event_StackOverflow. Even if I set

    hr = clrPolicyManager->SetActionOnFailure(FAIL_StackOverflow, eRudeUnloadAppDomain);

    Could someone at Microsoft give us a more full featured example of how to host the .NET runtime and use some of the more advanced features. In particular, I'm trying to host the runtime and configure it such that a StackOverflowException does not pull down other AppDomains. Isn't the purpose of having AppDomains to provide this sort of isolation?

    At any rate, some decent sample code would help the community out. It shouldn't take someone from that team to put a sample together. It takes for ever to try and figure this out by trial and error.
    Friday, July 23, 2010 8:39 PM

Answers

  • That's strange, it works fine for me with both .Net 2 and .Net 4, I register for the events as you do and set the same failure action and a stack overflow in an app domain that I've created gives the expected event and causes just that app domain to be unloaded.

    Of course a stack overflow in the default app domain brings everything down, but even that causes the event to be raised.

    I do have a comment in the code that I use to unregister events that says unregistering a stack overflow even fails with invalid parameter, but that's the only strangeness I've seen in this area.

     

     

    • Marked as answer by SamAgain Wednesday, August 4, 2010 5:36 AM
    Thursday, July 29, 2010 4:25 PM

All replies

  • That's strange, it works fine for me with both .Net 2 and .Net 4, I register for the events as you do and set the same failure action and a stack overflow in an app domain that I've created gives the expected event and causes just that app domain to be unloaded.

    Of course a stack overflow in the default app domain brings everything down, but even that causes the event to be raised.

    I do have a comment in the code that I use to unregister events that says unregistering a stack overflow even fails with invalid parameter, but that's the only strangeness I've seen in this area.

     

     

    • Marked as answer by SamAgain Wednesday, August 4, 2010 5:36 AM
    Thursday, July 29, 2010 4:25 PM
  • We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Please mark the right answer at right time.
    Thanks,
    Sam
    Wednesday, August 4, 2010 5:36 AM