Hi Peer,
My attempt at dealing with the StackOverflow issue was to put the TryConfigClr function (which I paste below) just before the call to CorBindToRuntimeEx around line 265 of ExcelDnaLoader.cpp. If this worked, there would still be a few things to sort out regarding loading the AppDomain, but I don't expect problems with these parts.
So our problem is that the call to
hr = pCLRControl->GetCLRManager(IID_ICLRPolicyManager, (PVOID*)&pCLRPolicyManager);
always fails with HOST_E_INVALIDOPERATION. In the Rotor code (where I expect the hosting part to be the same) in file clr\src\vm\CorHost.cpp, line 3516, it seems the only way this can happen is if the g_fEEStarted flag is set. In the debugger I can see that the CLR is only loaded when CorBindToRuntimeEx is called, and I don't call ->Start(). So maybe Excel or the VSTO add-in are interfering somehow.
This might need a bit of patience, or some CLR hosting expertise to sort out. I have some ideas on how to approach this, and although fascinating, it is not a high priority for me. In any event, one would not easily be able to change these settings if another add-in started the runtime.
Another way to make the add-ins robust is to host them out-of-process. This would be easy, but pretty much defeats the purpose, and there are other products that do this already.
Regards,
Govert
void TryConfigClr(pfnCorBindToRuntimeEx CorBindToRuntimeEx )
{
// If the CLR has not yet been loaded, it will be possible to configure some settings
// that improve the robustness of the runtime.
// For now we just try to configure stack overflow to unload the appdomain, not the
// whole Excel process.
//
// HRESULT hr = E_FAIL;
// CComPtr<ICLRRuntimeHost> pHost;
// hr = CorBindToRuntimeEx(L"v2.0.50727", L"wks", NULL, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*)&pHost);
// if (FAILED(hr))
// {
// // Just ignore and not try to set robust handling
// // - typically we expect HOST_E_INVALIDOPERATION
// // which indicated that the CLR has already started.
//#if _DEBUG
// DebugBreak();
//#endif
// return;
// }
//
// // Set up error handling for the runtime
// CComPtr<ICLRControl> pCLRControl;
// hr = pHost->GetCLRControl(&pCLRControl);
// if (FAILED(hr))
// {
// // Just ignore and not try to set robust handling
// // - typically we expect HOST_E_INVALIDOPERATION
// // which indicated that the CLR has already started.
//#if _DEBUG
// DebugBreak();
//#endif
// return;
// }
//
// ICLRGCManager *ppObject;
// hr = pCLRControl->GetCLRManager(IID_ICLRGCManager, (VOID **) &ppObject);
//
// ICLRPolicyManager* pCLRPolicyManager = NULL;
// hr = pCLRControl->GetCLRManager(IID_ICLRPolicyManager, (PVOID*)&pCLRPolicyManager);
// if (FAILED(hr))
// {
// if (hr == HOST_E_INVALIDOPERATION)
// {
//#if _DEBUG
// DebugBreak();
//#endif
// }
// else
// {
//#if _DEBUG
// DebugBreak();
//#endif
// }
// return;
// }
// hr = pCLRPolicyManager->SetActionOnFailure(FAIL_StackOverflow, eRudeUnloadAppDomain);
// if (FAILED(hr))
// {
// // Unexpected error
//#if _DEBUG
// DebugBreak();
//#endif
// return;
// }
}
-----Original Message-----
From:
exce...@googlegroups.com [mailto:
exce...@googlegroups.com] On Behalf Of Peer
Sent: 30 January 2009 10:01
To: ExcelDna
Subject: [ExcelDna] Re: Integration.RegisterMethods
Thanks Govert that solved my problem with Intergration.RegisterMethods
().
I am now creating a mini-IDE for the interactive python scripts to
control Excel. As such, I want to call Intergration.RegisterMethods()
from a button OnClick event. But it still fails for me.
My work around was simple: The OnClick event calls
Excel.Application.Run("ExcelCommandRegister") which in turn calls
Intergration.RegisterMethods() in the same way as your above .dna
example.
private void m_buttonRegister_Click(object sender, EventArgs e)
{
Excel.Application.Run("Register", Type.Missing x30 )
}
Thanks to ExcelDNA and your assistance with the dynamic method
registration my proof of concept project to embedded interactive
IronPython scripting into Excel has worked out well.
I definitely need to solve the StackOverflow and OutOfMemory
exceptions. I will try playing with the CLR hosting interfaces and if
find any solutions I will post back onto this thread.
Once I have made my tool more robust I will investigate making it
available for download.
> ...
>
> read more »