Logging block with Prism, Unity and WPF designtime data

Topics: Logging Application Block
Apr 25, 2011 at 4:44 PM

Hi folks,

I'm having a problem using the Ent5 logging block with WPF Designtime data. The applications work perfectly, but after I 'tacked on' the logging block, when I try to open the WPF form in the designer (the form uses design time data), the logging block can't be instanciated. The designer throws the exception "The type LogWriter cannot be constructed. You must configure the container to supply this value.". Fine, it's probably because the designer can't find the entlib config used by my main app (app.config). So I tried creating an app.config for the MVVM module I'm working on (copied the entlib config items to it from the main app.config) and still no joy. I know the problem is coming from my designtime class constructor as shown below (the ExtendedLogger class):

        public CornerPadDtViewModel() : base(new RegionManager(), new UnityContainer(), new ExtendedLogger())
            CornerPadVm = new UserInput
                                  SalesOrder = "XXXX1234567", blah, blah...

I'm not even sure how to mock it, because I'm not too sure why it's not finding my new 'local' app.config in the module I'm working on in the first place. The app runs great, logging is slick, it's just the design time data issue. (sigh)

Soooo... how in the world can I get my designtime class back if I'm using the logging block in the MVVM module and it uses constructor injection?

Thanks for any help here.

Apr 25, 2011 at 7:23 PM


Have you tried detecting the designer and preventing it from running code you don't want ran?  This is how I use to do it in WinForms.  Looks to be a little different here.

Apr 25, 2011 at 8:36 PM

Unfortunatly what I 'don't want run' is the constructor for the ViewModel, which of course is illogical, because I need to instanciate it with design data. The problem is that instaciating it throws the error on the log writer. I can't overload the ViewModel constructor to exclude the logwriter, that would break everything as far as Unity is concerned...

Detecting design mode is not an option here.


Apr 26, 2011 at 11:16 AM


I'm afraid this really doesn't look like an entlib specific problem and personally I'm not knowledgeable on MVVM as well, to be able to suggest anything. What I can only say is that you might have better answers from MVVM specific forums.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Apr 26, 2011 at 4:54 PM

OK, thanks I'll try over there...