Bug in DataPortal.IsInDesignMode

Bug in DataPortal.IsInDesignMode

Old forum URL: forums.lhotka.net/forums/t/6368.aspx


josh.wagoner posted on Friday, February 06, 2009

I am currently working on a WPF app that is using CSLA and I believe there is a bug in IsInDesignMode that causes it to throw an exception if the first time it is called is from within a layout pass. The call to Dispatcher.Invoke is the problem. Invoke results in a frame being pushed onto the dispatcher which cannot be done during layout because dispatcher processing is disabled during layout passes.

I think you can eliminate this call by simply changing the implementation of IsInDesignMode to something like this:

return DesignerProperties.GetIsInDesignMode(new DependencyObject());

The designers (at least Blend and VS) set the IsInDesignMode by overriding the default value of the DesignerProperties.IsInDesignMode property using OverrideMetadata. So, I believe this should work even if it is not executed on the Dispatcher thread and doesn't require the call to Invoke.

Josh

RockfordLhotka replied on Friday, February 06, 2009

Can you try your suggestion and see if it both works, and solves your issue?

Thanks!

josh.wagoner replied on Monday, February 09, 2009

Yeah, it works and solves our issue, but the team doesn't want to make any changes to the csla code itself. We ended up making a small change to the wpf code so that the first call to IsInDesignMode doesn't happen from within a layout pass.

RockfordLhotka replied on Monday, February 09, 2009

Ok. I was rather hoping you could make the recommended change in a copy of
the csla code to see if it solves your issue (without causing side-effects).
If so, I can more rapidly consider putting it into 3.6.2.

If I have to create a test scenario and run through the work to replicate
your problem that'll take me more time. I'll do it at some point - just
don't know exactly when.

Rocky


-----Original Message-----
From: josh.wagoner [mailto:cslanet@lhotka.net]
Sent: Monday, February 09, 2009 12:50 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Bug in DataPortal.IsInDesignMode

Yeah, it works and solves our issue, but the team doesn't want to make any
changes to the csla code itself. We ended up making a small change to the
wpf code so that the first call to IsInDesignMode doesn't happen from within
a layout pass.

Turntwo replied on Friday, March 20, 2009

I ran into a similar problem with DataPortal.IsInDesignMode, but for me it doesn't throw an exception.  It hangs the program ( I'm assuming some kind of deadlock ).  I'm not sure exactly what is happening, but it hangs on the Dispatcher.Invoke call.  The Main thread seems to be waiting on a lock(_managers) statement in GetRoles.  I don't know if that is relevant or a coincidence (although it always is stuck on that spot).  This only occurs when I open WPF forms with multiple CslaDataProviders.  Again not sure if that is the issue. 

So, I realize I don't have much information to help, but if an alternate implementation of IsInDesignMode works, I'd be interested.  For I used the same fix mentioned above - I call IsInDesignMode when the app loads, so I avoid the deadlock later. 

RockfordLhotka replied on Friday, March 20, 2009

I believe 3.6.2 now uses a simpler implementation that avoids the dispatcher.

 

Rocky

 

 

From: Turntwo [mailto:cslanet@lhotka.net]
Sent: Friday, March 20, 2009 5:49 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Bug in DataPortal.IsInDesignMode

 

I ran into a similar problem with DataPortal.IsInDesignMode, but for me it doesn't throw an exception.  It hangs the program ( I'm assuming some kind of deadlock ).  I'm not sure exactly what is happening, but it hangs on the Dispatcher.Invoke call.  The Main thread seems to be waiting on a lock(_managers) statement in GetRoles.  I don't know if that is relevant or a coincidence (although it always is stuck on that spot).  This only occurs when I open WPF forms with multiple CslaDataProviders.  Again not sure if that is the issue. 

So, I realize I don't have much information to help, but if an alternate implementation of IsInDesignMode works, I'd be interested.  For I used the same fix mentioned above - I call IsInDesignMode when the app loads, so I avoid the deadlock later. 


Copyright (c) Marimer LLC