Null reference when using element host.

Dec 3, 2010 at 5:43 AM

I am hosting a WPF control in a winform ap.

I am trying to create my root view (using caliburn) and add it to the ElementHost.

My code goes something like this

    public partial class WinForm
        public WinForm()
            var autofacBootStrapper = new AutofacBootStrapper();

            var viewModel = IoC.Get<MyViewModel>();
            var element = ViewLocator.LocateForModel(viewModel, null, null);
            ViewModelBinder.Bind(viewModel, element, null);

            elementHost1.Child = element;

The problem is that ViewModelBinder.Bind eventually calls Bootstrapper.IsInDesignMode and Application.Current.ToString(); throws a null reference.

My temporary fix was to modify Caliburn.Micro to use IsInDesignMode from MVVM Light

Am I doing it wrong ? :)

Some other relevant posts


Dec 3, 2010 at 2:57 PM

I'll add this as a bug. Detecting design mode on all platforms for all tools is way more difficult than it should be...

Dec 7, 2010 at 11:24 AM

I've also just run into this issue when running unit tests from Visual Studio, Application.Current is null.  Should the dependency on Application be abstracted and injected so that it can be mocked in unit tests as required?

Dec 7, 2010 at 3:06 PM

Fixed in d159a8bddd0e 

Dec 7, 2010 at 11:13 PM
Thanks Rob

On Wed, Dec 8, 2010 at 2:06 AM, EisenbergEffect
<> wrote:
> From: EisenbergEffect
> Fixed in d159a8bddd0e
> Read the full discussion online.
> To add a post to this discussion, reply to this email
> ([email removed]
> To start a new discussion for this project, email
> [email removed]
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at