Re: [Quickfix-developers] "Cannot pass a GCHandle across AppDomains"
Brought to you by:
orenmnero
From: Scott K. <sc...@la...> - 2010-08-06 18:52:14
|
Basically, I gave up on doing the project in .NET. I'm not sure that you're working with Excel, as I am, but Excel is unmanaged code, Qucikfix is natively unmanaged code, and I just felt it was throwing too much trouble in the mix to have some .NET bridge in the middle. I eventually get it working with C++ only... You can get it to work in .NET by not using VSTO as they create a "shim" which creates appdomains. .NET may possibly handle the part where you have to callback into Excel asynchronously more smoothly, as that was horrible in C++. On Fri, Aug 6, 2010 at 1:16 PM, Diego Frata <die...@gm...> wrote: > Scott, > > I believe you didn't received the email below. Marco has the same problem > with AppDomains and Quickfix you had sometime ago. I'm trying to help him > figure out, but we're having a hard time. Can you help us with any sample > code from your solution, so we could see how you managed to get it working? > > Thank you in advance. > > Diego Frata > die...@gm... > > > ---------- Forwarded message ---------- > From: goncalvm <mar...@pa...> > Date: Wed, Aug 4, 2010 at 5:03 PM > Subject: Re: [Quickfix-developers] "Cannot pass a GCHandle across > AppDomains" > To: qui...@li... > > > QuickFIX Documentation: > http://www.quickfixengine.org/quickfix/doc/html/index.html > QuickFIX Support: http://www.quickfixengine.org/services.html > > > 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. > > > > ------------------------------------------------------------------------------ > The Palm PDK Hot Apps Program offers developers who use the > Plug-In Development Kit to bring their C/C++ apps to Palm for a share > of $1 Million in cash or HP Products. Visit us here for more details: > http://p.sf.net/sfu/dev2dev-palm > _______________________________________________ > Quickfix-developers mailing list > Qui...@li... > https://lists.sourceforge.net/lists/listinfo/quickfix-developers > > |