Re: [Quickfix-developers] "Cannot pass a GCHandle across AppDomains"
Brought to you by:
orenmnero
From: goncalvm <mar...@pa...> - 2010-08-04 20:03:23
|
Hi Scott, I am having the same problem as yours. I am creating a VSTO addin and appdomain problem came up. I don't know anything about c++. Do you have any sample or any article in c#? I tried to build an ActiveX instead and it worked well, but when I press F2 (edit mode in Excel) I lost messages. Any help will be appreciated! Best regards, Marco Scott Kathrein wrote: > > QuickFIX Documentation: > http://www.quickfixengine.org/quickfix/doc/html/index.html > QuickFIX Support: http://www.quickfixengine.org/services.html > > > Well, I don't, I think. > > Visual studio was creating the AppDomains for me because I was creating a > Visual Studio Tools for Office project in visual studio 2008. (I believe > it > was creating a "shim"). I've reconfigured my project to create a plain old > class library, which I then register the same way with regasm, and this > works, presumably because there is no AppDomain creation. > > I was a little worried I wouldn't have much control over when Excel > creates > AppDomains and the like... but it seems to be working now. > > If this is a known issue, maybe it would make sense to post a warning > somewhere about the .NET wrapper? I've seen a couple people (1 of them > using > quickfix) have this problem when using NUnit, as it creates AppDomains and > apparently VSTO does so too. > > I wasn't sure at first exactly *how* I was passing a GCHandle across > appdomains. I mean, all of quickfix should be in the same appdomain, > right? > But the page I linked above seems to explain it pretty well. Apparently > unmanaged code doesn't *have* an appdomain, and so when it calls into > managed code, the compiler just *picks* a random one, namely the "first" > one, which in this case might have been the default Excel appdomain. > > The problem then is not caused by wanting to pass a handle between > appdomains, but rather by the simple *existance* of more than one > appdomain, > which consequently causes the compiler to bork and say "meh, this code's > not > managed, we'll just choose any old appdomain we feel like to handle this > callback!" > > The solution, is to use delegates, so the compiler knows which appdomain > to > use when unmanaged code goes into managed code. > > Losing the ability to use multiple appdomains has it's cost, most of which > I'm clueless about, not really being an expert on all this stuff. > > So that seems to be the long and short of it! Instead of posting a warning > about your wrapper, maybe microsoft should post a warning whenever you try > to use their compiler! (Or at least when unmanaged code calls back into > managed code.) > > Scott > > On Mon, Jun 21, 2010 at 7:21 PM, Diego Frata <die...@gm...> > wrote: > >> Scott, >> >> Why do you need to pass a GCHandle across AppDomains? >> >> Diego Frata >> die...@gm... >> >> >> On Mon, Jun 21, 2010 at 1:59 PM, Scott Kathrein < >> sc...@la...> wrote: >> >>> QuickFIX Documentation: >>> http://www.quickfixengine.org/quickfix/doc/html/index.html >>> QuickFIX Support: http://www.quickfixengine.org/services.html >>> >>> >>> >>> So here's the issue: I'm trying to create a COM object for use in Excel, >>> and I'm using the quickfix .NET wrapper API from version 1.13.3. I'm >>> compiling the quickfix library from source, but I have not made any >>> changes >>> to it. >>> >>> Most the time everything works fine, but when I do an >>> "initiator.start()", >>> at some point subsequently the Log class gets invoked to send out >>> "Connecting to x on port x", and I receive a "Cannot pass a GCHandle >>> across >>> AppDomains" exception that occurs when the onEvent method of the Log >>> class >>> is (attempted to be) accessed. >>> >>> If this is what it looks like, then the solution is very complicated and >>> uses delegates, and possibly a total rewrite of the .NET wrapper: >>> http://lambert.geek.nz/2007/05/29/unmanaged-appdomain-callback/ >>> >>> This appears to be a long standing problem with Quickfix. I've found a >>> number of people receiving this exception. >>> For example, here: >>> http://article.gmane.org/gmane.comp.finance.quickfix.user/1362 (2009, >>> has >>> workaround) >>> or here: http://osdir.com/ml/finance.quickfix.user/2006-10/msg00019.html >>> (from >>> 2006, says he contacted another user wit the same problem who had to >>> develop >>> his own fix implementation) >>> >>> Right now I can't directly search the mailing list (any search I do >>> returns no results), so I guess my questions are this: >>> >>> Is this still a known problem with Quickfix and appdomains? Is the only >>> real workaround to ensure that all of quickfix runs in one appdomain? >>> >>> If so, I'll have to look into doing that, or considering whether this >>> project should be abandoned. It's not clear to me if it's possible to >>> always >>> ensure something is running in one appdomain, and I'd rather not invest >>> a >>> lot of time into this and have it run buggy. >>> >>> Scott >>> >>> >>> ------------------------------------------------------------------------------ >>> ThinkGeek and WIRED's GeekDad team up for the Ultimate >>> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the >>> lucky parental unit. See the prize list and enter to win: >>> http://p.sf.net/sfu/thinkgeek-promo >>> _______________________________________________ >>> Quickfix-developers mailing list >>> Qui...@li... >>> https://lists.sourceforge.net/lists/listinfo/quickfix-developers >>> >> >> > > ------------------------------------------------------------------------------ > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > _______________________________________________ > Quickfix-developers mailing list > Qui...@li... > https://lists.sourceforge.net/lists/listinfo/quickfix-developers > -- View this message in context: http://old.nabble.com/%22Cannot-pass-a-GCHandle-across-AppDomains%22-tp28951594p29350639.html Sent from the QuickFIX - Dev mailing list archive at Nabble.com. |